context = window

MixerActions = @MixerActions

@SessionRecordedCategory = React.createClass({

  propTypes: {
    mode: React.PropTypes.bool.isRequired
  }

  handleMute: (e) ->
    e.preventDefault()

    muting = $(e.currentTarget).is('.enabled')

    # this button is annoying. the hover shows mute and it's good to use instead
    # MixerActions.mute([this.props.mixers.mixer, this.props.mixers.oppositeMixer], muting)

  render: () ->

    # today, all mixers are the same for a remote participant; so just grab the 1st
    mixers = @props.mixers

    muteMixer = mixers.muteMixer
    vuMixer = mixers.vuMixer
    muteMixerId = muteMixer?.id

    classes = classNames({
      'track-icon-mute': true
      'enabled' : !muteMixer?.mute
      'muted' : muteMixer?.mute
    })

    componentClasses = classNames({
      "session-track" : true
      "recorded-category" : true
    })

    pan = mixers.mixer.pan

    panStyle = {
      transform: "rotate(#{pan}deg)"
      WebkitTransform: "rotate(#{pan}deg)"
    }

    `<div className={componentClasses}>
      <div className="session-track-contents">
        <div className="name">{this.props.recordingName}</div>
        <div className="track-controls">
          <SessionTrackVU orientation="horizontal" lightCount={4} lightWidth={17} lightHeight={3} side="best" mixers={mixers} />
          <div className="track-buttons">
            <div className="track-icon-pan" style={panStyle}/>
            <div className={classes} data-control="mute" data-mixer-id={muteMixerId} onClick={this.handleMute}/>
          </div>
          <br className="clearall"/>
        </div>

        <br className="clearall"/>
      </div>
    </div>`

  componentDidMount: () ->


    $root = $(this.getDOMNode())
    $mute = $root.find('.track-icon-mute')
    $pan  = $root.find('.track-icon-pan')

    context.JK.interactReactBubble(
      $mute,
      'SessionTrackVolumeHover',
      () =>
        {mixers:@props.mixers, trackType: 'SessionRecordedCategory', mode: @props.mode}
    ,
      {width:235, positions:['right', 'left'], offsetParent:$root.closest('.top-parent')})

    context.JK.interactReactBubble(
      $pan,
      'SessionTrackPanHover',
      () =>
        {mixers:@props.mixers}
    ,
      {width:331, positions:['right', 'left'], offsetParent:$root.closest('.top-parent')})

})