'use strict';

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

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _styledComponents = require('styled-components');

var _styledComponents2 = _interopRequireDefault(_styledComponents);

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Container = _styledComponents2.default.div.withConfig({
  displayName: 'RadioButton__Container'
})(['flex: 1 1 auto;&:first-of-type > label {border-radius: 3px 0 0 3px;}&:first-of-type > label::after {border-radius: 0 0 0 3px;}&:last-of-type > label {border-radius: 0 3px 3px 0;}&:last-of-type > label::after {border-radius: 0 0 3px 0;}']);

var Input = _styledComponents2.default.input.withConfig({
  displayName: 'RadioButton__Input'
})(['display: none;']);

var Label = _styledComponents2.default.label.withConfig({
  displayName: 'RadioButton__Label'
})(['opacity: ', ';border: ', ';margin-right: -1px;padding: ', ';cursor: pointer;position: relative;display: flex;flex-direction: column;align-content: flex-start;background: ', ';color: ', ';transition: opacity 0.2s ease;text-transform: uppercase;font-weight: bold;height: 100%;&::after {content: "";background: ', ';width: calc(100% + 2px);height: ', ';position: absolute;bottom: -1px;left: -1px;display: block;transition: height 0.2s ease, opacity 0.2s ease;}&:hover::after {height: 5px;opacity: 0.5;}'], function (_ref) {
  var active = _ref.active;
  return active ? 1 : 0.5;
}, function (_ref2) {
  var theme = _ref2.theme;
  return theme.radioButton.border;
}, function (_ref3) {
  var theme = _ref3.theme;
  return theme.radioButton.padding;
}, function (_ref4) {
  var theme = _ref4.theme;
  return theme.radioButton.bg;
}, function (_ref5) {
  var theme = _ref5.theme;
  return theme.radioButton.fg;
}, function (_ref6) {
  var theme = _ref6.theme;
  return theme.radioButton.accent;
}, function (_ref7) {
  var active = _ref7.active;
  return active ? '5px' : 0;
});

var Content = _styledComponents2.default.figure.withConfig({
  displayName: 'RadioButton__Content'
})(['font-size: 2em;font-weight: 100;margin: auto auto auto 0;']);

var LabelText = _styledComponents2.default.span.withConfig({
  displayName: 'RadioButton__LabelText'
})(['font-size: inherit;font-weight: inherit;color: inherit;margin: auto auto auto 0;']);

var RadioButton = function (_React$Component) {
  _inherits(RadioButton, _React$Component);

  function RadioButton() {
    _classCallCheck(this, RadioButton);

    return _possibleConstructorReturn(this, (RadioButton.__proto__ || Object.getPrototypeOf(RadioButton)).apply(this, arguments));
  }

  _createClass(RadioButton, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          checked = _props.checked,
          label = _props.label,
          name = _props.name,
          value = _props.value,
          onChange = _props.onChange,
          content = _props.content;

      var id = 'radio-' + name + '>' + value;

      return _react2.default.createElement(
        Container,
        null,
        _react2.default.createElement(Input, { type: 'radio', id: id, value: value, name: name, checked: checked, onChange: onChange }),
        _react2.default.createElement(
          Label,
          { htmlFor: id, active: checked },
          content !== null ? _react2.default.createElement(
            Content,
            { active: checked },
            content
          ) : null,
          _react2.default.createElement(
            LabelText,
            null,
            label
          )
        )
      );
    }
  }]);

  return RadioButton;
}(_react2.default.Component);

RadioButton.propTypes = {
  checked: _propTypes2.default.bool.isRequired,
  onChange: _propTypes2.default.func.isRequired,
  label: _propTypes2.default.string.isRequired,
  content: _propTypes2.default.node,
  name: _propTypes2.default.string.isRequired,
  value: _propTypes2.default.string.isRequired
};
RadioButton.defaultProps = {
  content: null
};


RadioButton.usage = '\n# RadioButton\n\nNot really meant to be used alone, unless you just want the styling of it. Use RadioGroup to create a group of RadioButtons.\n';

exports.default = RadioButton;