context = window
rest = context.JK.Rest()
SessionActions = @SessionActions
MIX_MODES = context.JK.MIX_MODES
EVENTS = context.JK.EVENTS
ChannelGroupIds = context.JK.ChannelGroupIds

@SessionMasterMediaTracks = React.createClass({

  mixins: [@SessionMediaTracksMixin, Reflux.listenTo(@SessionMediaTracksStore,"onInputsChanged"), Reflux.listenTo(@AppStore,"onAppInit")]

  render: () ->

    mediaTracks = []

    if this.state.mediaSummary.mediaOpen

      if this.state.mediaSummary.backingTrackOpen

        for backingTrack in @state.backingTracks
          backingTrack.mode = MIX_MODES.MASTER
          mediaTracks.push(`<SessionBackingTrack key={backingTrack.track.id} {...backingTrack} />`)

      else if this.state.mediaSummary.jamTrackOpen

        mediaTracks.push(`<SessionJamTrackCategory key="JamTrackCategory" jamTrackName={this.state.jamTrackName} mixers={this.state.mediaCategoryMixer} mode={MIX_MODES.MASTER} />`)
        for jamTrack in @state.jamTracks
          jamTrack.mode = MIX_MODES.MASTER
          mediaTracks.push(`<SessionJamTrack key={jamTrack.id} {...jamTrack} />`)

      else if this.state.mediaSummary.recordingOpen

        mediaTracks.push(`<SessionRecordedCategory key="RecordedCategory" recordingName={this.state.recordingName} mixers={this.state.mediaCategoryMixer} mode={MIX_MODES.MASTER} />`)
        for recordedTrack in @state.recordedTracks
          recordedTrack.mode = MIX_MODES.MASTER
          mediaTracks.push(`<SessionRecordedTrack key={recordedTrack.track.id} {...recordedTrack} />`)

      else if this.state.mediaSummary.metronomeOpen

        @state.metronome.mode = MIX_MODES.MASTER
        mediaTracks.push(`<SessionMetronome key={this.state.metronome.id} {...this.state.metronome} />`)

    `<div className="session-media-tracks">
      <h2>recorded audio</h2>
      <div className="session-tracks-scroller">
        {mediaTracks}
      </div>
    </div>`


  getInitialState:() ->
    {mediaSummary:{mediaOpen: false}, isRecording: false, backingTracks: [], jamTracks: [], recordedTracks: [], metronome: null}

  onAppInit: (app) ->
    @app = app





})
