React = require 'react'

{input, label, span} = React.DOM


CheckboxInput = React.createClass

  displayName: 'CheckboxInput'

  getDefaultProps: ->
    className: 'checkbox-input'
    disabled: false
    wrapperLabel: null

  render: ->
    {className, onChange, wrapperLabel, checked, disabled, id, tabIndex} = @props

    inputProps = 
      key: 'input'
      ref: 'input'
      type: 'checkbox'
      onChange: onChange
      checked: checked
      disabled: disabled

    inputProps.tabIndex = tabIndex if tabIndex?
    inputProps.id = id if id?
    inputProps.className = className if className?

    if wrapperLabel?
      label {
        className: 'checkbox-input-label'
        htmlFor: id
      }, [
        input(inputProps)
        span {
          key: 'label'
        }, wrapperLabel
      ]
    else
      input(inputProps)

  getValue: ->
    return @refs.input.checked


module.exports = CheckboxInput