'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _recompose = require('recompose');

var _RadioGroupButtonContainer = require('./styles/RadioGroupButtonContainer');

var _RadioGroupButtonContainer2 = _interopRequireDefault(_RadioGroupButtonContainer);

var _RadioGroupButtonContent = require('./styles/RadioGroupButtonContent');

var _RadioGroupButtonContent2 = _interopRequireDefault(_RadioGroupButtonContent);

var _RadioGroupButtonInput = require('./styles/RadioGroupButtonInput');

var _RadioGroupButtonInput2 = _interopRequireDefault(_RadioGroupButtonInput);

var _RadioGroupButtonLabel = require('./styles/RadioGroupButtonLabel');

var _RadioGroupButtonLabel2 = _interopRequireDefault(_RadioGroupButtonLabel);

var _RadioGroupButtonLabelText = require('./styles/RadioGroupButtonLabelText');

var _RadioGroupButtonLabelText2 = _interopRequireDefault(_RadioGroupButtonLabelText);

var _RadioGroupContainer = require('./styles/RadioGroupContainer');

var _RadioGroupContainer2 = _interopRequireDefault(_RadioGroupContainer);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * A stylized `<input type="radio">` meant to be used in a
 * group with others. Reference the group container by `RadioButton.Group`.
 */
var RadioButton = function (_React$Component) {
  (0, _inherits3.default)(RadioButton, _React$Component);

  function RadioButton() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, RadioButton);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = RadioButton.__proto__ || (0, _getPrototypeOf2.default)(RadioButton)).call.apply(_ref, [this].concat(args))), _this), _this.renderChildren = function () {
      var _this$props = _this.props,
          children = _this$props.children,
          checked = _this$props.checked;


      if (typeof children === 'function') {
        return children({ checked: checked });
      }

      return children;
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(RadioButton, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          checked = _props.checked,
          label = _props.label,
          name = _props.name,
          value = _props.value,
          disabled = _props.disabled,
          onChange = _props.onChange,
          children = _props.children,
          className = _props.className,
          Container = _props.Container,
          Content = _props.Content,
          Input = _props.Input,
          Label = _props.Label,
          LabelText = _props.LabelText;


      var id = this.props.id || 'radio-' + name + '>' + value;

      return _react2.default.createElement(
        Container,
        { className: disabled && 'disabled' },
        _react2.default.createElement(Input, {
          type: 'radio',
          id: id,
          value: value,
          name: name,
          checked: checked,
          onChange: onChange,
          className: className,
          disabled: disabled
        }),
        _react2.default.createElement(
          Label,
          { htmlFor: id, active: checked, disabled: disabled },
          _react2.default.createElement(
            LabelText,
            null,
            label
          ),
          children && _react2.default.createElement(
            Content,
            null,
            this.renderChildren()
          )
        )
      );
    }
  }]);
  return RadioButton;
}(_react2.default.Component);

RadioButton.propTypes = {
  /**
   * Whether or not the button is currently selected.
   * Use undefined to make this an 'uncontrolled' component
   */
  checked: _propTypes2.default.bool,
  /**
   * Called when the checked state of the button changes.
   */
  onChange: _propTypes2.default.func,
  /**
   * Text to render inside the button's label.
   */
  label: _propTypes2.default.string.isRequired,
  /**
   * Content to render inside the main part of the button. You can pass
   * a node, string, or a function. If a function is passed, it receives
   * a parameter `{ checked: boolean }` and should return a node.
   */
  children: _propTypes2.default.oneOfType([_propTypes2.default.node, _propTypes2.default.string, _propTypes2.default.func]),
  /**
   * A field name for the input.
   */
  name: _propTypes2.default.string.isRequired,
  /**
   * The input value.
   */
  value: _propTypes2.default.string.isRequired,
  /**
   * If true, user cannot interact with this button.
   */
  disabled: _propTypes2.default.bool,
  /**
   * Adds a class name to the input element.
   */
  className: _propTypes2.default.string,
  /**
   * Adds an id to the input element.
   */
  id: _propTypes2.default.string,
  /**
   * A component to render the container around the button
   */
  Container: _propTypes2.default.func,
  /**
   * A component to render the content inside the button (not the label)
   */
  Content: _propTypes2.default.func,
  /**
   * A component to render the input for the button (usually hidden)
   */
  Input: _propTypes2.default.func,
  /**
   * A component to render the label inside the button
   */
  Label: _propTypes2.default.func,
  /**
   * A component to render the text inside the label
   */
  LabelText: _propTypes2.default.func
};
RadioButton.defaultProps = {
  content: null,
  className: null,
  id: null,
  disabled: false,
  Container: _RadioGroupButtonContainer2.default,
  Content: _RadioGroupButtonContent2.default,
  Input: _RadioGroupButtonInput2.default,
  Label: _RadioGroupButtonLabel2.default,
  LabelText: _RadioGroupButtonLabelText2.default
};
RadioButton.Small = (0, _recompose.withProps)({
  Label: _RadioGroupButtonLabel2.default.Small
})(RadioButton);
RadioButton.Large = (0, _recompose.withProps)({
  Label: _RadioGroupButtonLabel2.default.Large
})(RadioButton);
RadioButton.Group = _RadioGroupContainer2.default;
exports.default = RadioButton;