context = window
logger = context.JK.logger

@TeacherStudentLevel = React.createClass({

  mixins: [ICheckMixin]

  componentDidMount: () ->
    @checkboxes = [{selector: 'input.student-level', stateKey: 'checked'}]

    @root = $(@getDOMNode())

    @iCheckify()

  componentDidUpdate: () ->

    @iCheckify()

  checkboxChanged:(e) ->
    checked = $(e.target).is(':checked')

    value = $(e.target).val()

    #@setState({checked: value})

    @studentLevelChanged(this.props.student, e)

  render: () ->
    `<span>
      <input objectName={this.props.student} type="checkbox" className="student-level" onChange={this.studentLevelChanged.bind(this, this.props.student)} checked={this.state.checked}/>
      <span className="student-level">{this.props.display}</span>
    </span>`

  studentLevelChanged: (level, e) ->
    @setState({checked: $(e.target).is(':checked') })

    @props.onChange(this.props.student, $(e.target).is(':checked'))

  getInitialState: () ->
    {checked:@props.level}

  componentWillReceiveProps: (nextProps) ->
    @setState({checked: nextProps.level})
})