text: 'use strict';
  
  var _inherits = require('babel-runtime/helpers/inherits')['default'];
  
  var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];
  
  var _extends = require('babel-runtime/helpers/extends')['default'];
  
  var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];
  
  exports.__esModule = true;
  
  var _react = require('react');
  
  var _react2 = _interopRequireDefault(_react);
  
  var _classnames = require('classnames');
  
  var _classnames2 = _interopRequireDefault(_classnames);
  
  var _FormGroup = require('./FormGroup');
  
  var _FormGroup2 = _interopRequireDefault(_FormGroup);
  
  var _Glyphicon = require('./Glyphicon');
  
  var _Glyphicon2 = _interopRequireDefault(_Glyphicon);
  
  var InputBase = (function (_React$Component) {
    _inherits(InputBase, _React$Component);
  
    function InputBase() {
      _classCallCheck(this, InputBase);
  
      _React$Component.apply(this, arguments);
    }
  
    InputBase.prototype.getInputDOMNode = function getInputDOMNode() {
      return _react2['default'].findDOMNode(this.refs.input);
    };
  
    InputBase.prototype.getValue = function getValue() {
      if (this.props.type === 'static') {
        return this.props.value;
      } else if (this.props.type) {
        if (this.props.type === 'select' && this.props.multiple) {
          return this.getSelectedOptions();
        }
        return this.getInputDOMNode().value;
      }
      throw new Error('Cannot use getValue without specifying input type.');
    };
  
    InputBase.prototype.getChecked = function getChecked() {
      return this.getInputDOMNode().checked;
    };
  
    InputBase.prototype.getSelectedOptions = function getSelectedOptions() {
      var values = [];
  
      Array.prototype.forEach.call(this.getInputDOMNode().getElementsByTagName('option'), function (option) {
        if (option.selected) {
          var value = option.getAttribute('value') || option.innerHtml;
          values.push(value);
        }
      });
  
      return values;
    };
  
    InputBase.prototype.isCheckboxOrRadio = function isCheckboxOrRadio() {
      return this.props.type === 'checkbox' || this.props.type === 'radio';
    };
  
    InputBase.prototype.isFile = function isFile() {
      return this.props.type === 'file';
    };
  
    InputBase.prototype.renderInputGroup = function renderInputGroup(children) {
      var addonBefore = this.props.addonBefore ? _react2['default'].createElement(
        'span',
        { className: 'input-group-addon', key: 'addonBefore' },
        this.props.addonBefore
      ) : null;
  
      var addonAfter = this.props.addonAfter ? _react2['default'].createElement(
        'span',
        { className: 'input-group-addon', key: 'addonAfter' },
        this.props.addonAfter
      ) : null;
  
      var buttonBefore = this.props.buttonBefore ? _react2['default'].createElement(
        'span',
        { className: 'input-group-btn' },
        this.props.buttonBefore
      ) : null;
  
      var buttonAfter = this.props.buttonAfter ? _react2['default'].createElement(
        'span',
        { className: 'input-group-btn' },
        this.props.buttonAfter
      ) : null;
  
      var inputGroupClassName = undefined;
      switch (this.props.bsSize) {
        case 'small':
          inputGroupClassName = 'input-group-sm';break;
        case 'large':
          inputGroupClassName = 'input-group-lg';break;
        default:
      }
  
      return addonBefore || addonAfter || buttonBefore || buttonAfter ? _react2['default'].createElement(
        'div',
        { className: _classnames2['default'](inputGroupClassName, 'input-group'), key: 'input-group' },
        addonBefore,
        buttonBefore,
        children,
        addonAfter,
        buttonAfter
      ) : children;
    };
  
    InputBase.prototype.renderIcon = function renderIcon() {
      if (this.props.hasFeedback) {
        if (this.props.feedbackIcon) {
          return _react2['default'].cloneElement(this.props.feedbackIcon, { formControlFeedback: true });
        }
  
        switch (this.props.bsStyle) {
          case 'success':
            return _react2['default'].createElement(_Glyphicon2['default'], { formControlFeedback: true, glyph: 'ok', key: 'icon' });
          case 'warning':
            return _react2['default'].createElement(_Glyphicon2['default'], { formControlFeedback: true, glyph: 'warning-sign', key: 'icon' });
          case 'error':
            return _react2['default'].createElement(_Glyphicon2['default'], { formControlFeedback: true, glyph: 'remove', key: 'icon' });
          default:
            return _react2['default'].createElement('span', { className: 'form-control-feedback', key: 'icon' });
        }
      } else {
        return null;
      }
    };
  
    InputBase.prototype.renderHelp = function renderHelp() {
      return this.props.help ? _react2['default'].createElement(
        'span',
        { className: 'help-block', key: 'help' },
        this.props.help
      ) : null;
    };
  
    InputBase.prototype.renderCheckboxAndRadioWrapper = function renderCheckboxAndRadioWrapper(children) {
      var classes = {
        'checkbox': this.props.type === 'checkbox',
        'radio': this.props.type === 'radio'
      };
  
      return _react2['default'].createElement(
        'div',
        { className: _classnames2['default'](classes), key: 'checkboxRadioWrapper' },
        children
      );
    };
  
    InputBase.prototype.renderWrapper = function renderWrapper(children) {
      return this.props.wrapperClassName ? _react2['default'].createElement(
        'div',
        { className: this.props.wrapperClassName, key: 'wrapper' },
        children
      ) : children;
    };
  
    InputBase.prototype.renderLabel = function renderLabel(children) {
      var classes = {
        'control-label': !this.isCheckboxOrRadio()
      };
      classes[this.props.labelClassName] = this.props.labelClassName;
  
      return this.props.label ? _react2['default'].createElement(
        'label',
        { htmlFor: this.props.id, className: _classnames2['default'](classes), key: 'label' },
        children,
        this.props.label
      ) : children;
    };
  
    InputBase.prototype.renderInput = function renderInput() {
      if (!this.props.type) {
        return this.props.children;
      }
  
      switch (this.props.type) {
        case 'select':
          return _react2['default'].createElement(
            'select',
            _extends({}, this.props, { className: _classnames2['default'](this.props.className, 'form-control'), ref: 'input', key: 'input' }),
            this.props.children
          );
        case 'textarea':
          return _react2['default'].createElement('textarea', _extends({}, this.props, { className: _classnames2['default'](this.props.className, 'form-control'), ref: 'input', key: 'input' }));
        case 'static':
          return _react2['default'].createElement(
            'p',
            _extends({}, this.props, { className: _classnames2['default'](this.props.className, 'form-control-static'), ref: 'input', key: 'input' }),
            this.props.value
          );
        default:
          var className = this.isCheckboxOrRadio() || this.isFile() ? '' : 'form-control';
          return _react2['default'].createElement('input', _extends({}, this.props, { className: _classnames2['default'](this.props.className, className), ref: 'input', key: 'input' }));
      }
    };
  
    InputBase.prototype.renderFormGroup = function renderFormGroup(children) {
      return _react2['default'].createElement(
        _FormGroup2['default'],
        this.props,
        children
      );
    };
  
    InputBase.prototype.renderChildren = function renderChildren() {
      return !this.isCheckboxOrRadio() ? [this.renderLabel(), this.renderWrapper([this.renderInputGroup(this.renderInput()), this.renderIcon(), this.renderHelp()])] : this.renderWrapper([this.renderCheckboxAndRadioWrapper(this.renderLabel(this.renderInput())), this.renderHelp()]);
    };
  
    InputBase.prototype.render = function render() {
      var children = this.renderChildren();
      return this.renderFormGroup(children);
    };
  
    return InputBase;
  })(_react2['default'].Component);
  
  InputBase.propTypes = {
    type: _react2['default'].PropTypes.string,
    label: _react2['default'].PropTypes.node,
    help: _react2['default'].PropTypes.node,
    addonBefore: _react2['default'].PropTypes.node,
    addonAfter: _react2['default'].PropTypes.node,
    buttonBefore: _react2['default'].PropTypes.node,
    buttonAfter: _react2['default'].PropTypes.node,
    bsSize: _react2['default'].PropTypes.oneOf(['small', 'medium', 'large']),
    bsStyle: _react2['default'].PropTypes.oneOf(['success', 'warning', 'error']),
    hasFeedback: _react2['default'].PropTypes.bool,
    feedbackIcon: _react2['default'].PropTypes.node,
    id: _react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.string, _react2['default'].PropTypes.number]),
    groupClassName: _react2['default'].PropTypes.string,
    wrapperClassName: _react2['default'].PropTypes.string,
    labelClassName: _react2['default'].PropTypes.string,
    multiple: _react2['default'].PropTypes.bool,
    disabled: _react2['default'].PropTypes.bool,
    value: _react2['default'].PropTypes.any
  };
  
  InputBase.defaultProps = {
    disabled: false,
    hasFeedback: false,
    multiple: false
  };
  
  exports['default'] = InputBase;
  module.exports = exports['default'];