context = window

MixerActions = @MixerActions

@SessionMyChat = React.createClass({

  mixins: [@MasterPersonalMixersMixin]


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

    mixers = @mixers()
    unless mixers.mixer
      logger.debug("ignoring mute; no mixer")
      return

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

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

  render: () ->

    mixers = @mixers()
    muteMixer = mixers.muteMixer
    vuMixer = mixers.vuMixer
    muteMixerId = muteMixer?.id

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


    # <div className="track-icon-equalizer" />

    `<div className="session-track chat-track">
      <div className="disabled-track-overlay" />
      <div className="session-track-contents">
        <div className="name">{this.props.name}</div>
        <div className="track-avatar"><img src={this.props.photoUrl}/></div>
        <div className="track-instrument"><img height="45" src='/assets/content/icon_instrument_headphones45.png' width="45" /></div>
        <div className="track-controls">
          <SessionTrackVU orientation="horizontal" lightCount={4} lightWidth={17} lightHeight={3} side="best" mixers={mixers} />
          <div className="track-buttons">
            <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')

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