 @todo
 ###
 
-Autocomplete  = require '../autocomplete'
-Dropdown      = require '../dropdown'
-Input         = require '../input'
-Switch        = require '../switch'
+# -- Components
+Autocomplete           = require './autocomplete'
+Dropdown               = require './dropdown'
+Input                  = require './input'
+Switch                 = require './switch'
+# -- Constants
+TYPE =
+  AUTOCOMPLETE: 'autocomplete'
+  CHECKBOX    : 'checkbox'
+  DROPDOWN    : 'dropdown'
+  LABEL       : 'label'
+  RADIO       : 'radio'
+  SWITCH      : 'switch'
 
 module.exports = React.createClass
 

    attributes        : React.PropTypes.array
    className         : React.PropTypes.string
    label             : React.PropTypes.string
    onChange          : React.PropTypes.func

  getDefaultProps: ->
    attributes        : []

  getInitialState: ->
    attributes        : @props.attributes
    value_object      : _determineTypeOfValue @props.attributes

  # -- Lifecycle
  componentWillReceiveProps: (next_props) ->
    if attributes = next_props.attributes
      @setState attributes: attributes, value_object: _determineTypeOfValue attributes
      @setValue attributes

  # -- Events
  onChange: (event) ->
    unless @state.value_object
      for ref, el of @refs when el.refs.input.getDOMNode() isnt event.target
        el.setValue false



  getValue: ->
    value = {}
    if @state.type isnt TYPE.RADIO
      value[ref] = input.getValue() for ref, input of @refs when input.getValue?
    else
      value = ref for ref, input of @refs when input.getValue?() is true
    value

  setValue: (data = {}) ->
    if data instanceof Object
      @refs[key]?.setValue? value for key, value of data
    else
      @refs[key].setValue? key is data for key of @refs

# -- Internal methods
_determineType = (attributes) ->
  type = ''
  group_radio     = true
  group_checkbox  = true
  for attribute in attributes when attribute.type isnt TYPE.LABEL
    group_radio = false if attribute.type isnt TYPE.RADIO
    group_checkbox = false if attribute.type isnt TYPE.CHECKBOX
  type = TYPE.RADIO if group_radio
  type = TYPE.CHECKBOX if group_checkbox
  type
