import React from 'react';
import { isEmptyRadio } from '../../utils/validate';
import FieldWrapper from './FieldWrapper';
import withField from './withField'; // individual radio button, applies state-template styling

var RadioButton = function RadioButton(_ref) {
  var input = _ref.input,
      value = _ref.value,
      label = _ref.label,
      primary = _ref.primary,
      disabled = _ref.disabled;
  var checked = input.value.toString().indexOf(value) !== -1;

  var onChange = function onChange() {
    return input.onChange(value);
  };

  var inputProps = {
    disabled: disabled,
    checked: checked,
    onChange: onChange,
    type: 'radio',
    name: input.name
  };

  if (primary) {
    return React.createElement("label", {
      className: 'check'
    }, React.createElement("input", Object.assign({
      className: 'hidden-up pos-abs top-0 left-0'
    }, inputProps)), React.createElement("span", {
      className: 'btn btn-lg btn-block bg-highlight--checked rounded-0'
    }, label));
  }

  return React.createElement("label", {
    className: 'form-check-inline p-l-md m-l-0 m-r-md'
  }, React.createElement("input", Object.assign({
    className: 'hidden-up pos-abs'
  }, inputProps)), React.createElement("div", {
    className: 'check-icon-radio'
  }, React.createElement("i", null)), label);
}; // group of radio buttons with optional help text and label
// displays error if validation fails


var FieldRadioButtons = function FieldRadioButtons(props) {
  var input = props.input,
      options = props.options,
      primary = props.primary,
      disabled = props.disabled;
  var disabledClass = disabled ? 'disabled' : '';
  return React.createElement(FieldWrapper, props, React.createElement("div", {
    className: disabledClass
  }, options.filter(function (x) {
    return !x.hidden;
  }).map(function (option) {
    return React.createElement(RadioButton, Object.assign({
      input: input,
      key: option.value,
      primary: primary,
      disabled: disabled
    }, option));
  })));
};

FieldRadioButtons.defaultProps = {
  primary: false,
  disabled: false
};
var withReduxField = withField(isEmptyRadio);
export default withReduxField(FieldRadioButtons);