function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import uuid from 'uuid';
import MarkdownLabel from './MarkdownLabel';

class Radio extends PureComponent {
  constructor(props) {
    super(props);
    this.id = uuid();
  }

  render() {
    const {
      label,
      className,
      input,
      disabled,
      fieldLabel,
      ...rest
    } = this.props;
    const componentClasses = cx('form-field-radio', className, {
      'form-field-radio--disabled': disabled
    });
    return /*#__PURE__*/React.createElement("label", {
      className: componentClasses,
      htmlFor: this.id
    }, /*#__PURE__*/React.createElement("input", _extends({
      type: "radio",
      className: "form-field-radio__input",
      id: this.id // input.checked is only provided by redux form if type="checkbox" or type="radio" is
      // provided to <Field />, so for the case that it isn't we can rely on the more reliable
      // input.value
      ,
      checked: !!input.value // eslint-disable-next-line react/jsx-props-no-spreading

    }, input, rest)), /*#__PURE__*/React.createElement("div", {
      className: "form-field-radio__radio"
    }), label && /*#__PURE__*/React.createElement(MarkdownLabel, {
      inline: true,
      label: label,
      className: "form-field-inline-label"
    }));
  }

}

Radio.propTypes = {
  label: PropTypes.node,
  fieldLabel: PropTypes.string,
  className: PropTypes.string,
  disabled: PropTypes.bool,
  input: PropTypes.object.isRequired
};
Radio.defaultProps = {
  className: '',
  label: null,
  fieldLabel: null,
  disabled: false
};
export default Radio;