import React__default from 'react';
import Radio from '../radio/index.js';
import PropTypes from 'prop-types';
import { useField } from '../use-form/index.js';
import '../extends-e61fd370.js';
import '../defineProperty-18999f8e.js';
import '../objectWithoutProperties-72d23964.js';
import 'classnames';
import '../slicedToArray-5b664d46.js';
import '../index-81a9bdac.js';
import '../typeof-6c6d8d7a.js';
import '../auto-id.esm-2b54f757.js';
import '../utils.esm-514fad91.js';
import '../warning-ed2bf294.js';
import '../_commonjsHelpers-57e89916.js';
import '../use-progress/index.js';
import '../use-trailing-debounce/index.js';

function RadioField(_ref) {
  var id = _ref.id,
      name = _ref.name,
      label = _ref.label,
      value = _ref.value,
      onChange = _ref.onChange,
      checked = _ref.checked;
  // Value should not be passed into useField hook, because it would
  // override current form's value.
  var field = useField({
    id: id,
    name: name,
    onChange: onChange
  }); // Radiobutton is checked when cheched state is forced by props (controlled mode)
  // or current form value matches this radio's value

  var checkDefined = typeof checked !== "undefined";
  var isChecked = checkDefined && checked || !checkDefined && value === field.value;
  return /*#__PURE__*/React__default.createElement("div", {
    className: "flex items-center"
  }, /*#__PURE__*/React__default.createElement(Radio, {
    id: field.id,
    name: name,
    onBlur: field.onBlur,
    onChange: field.onChange,
    checked: isChecked,
    value: value
  }), /*#__PURE__*/React__default.createElement("label", {
    className: "ml-2 mb-0 font-sans text-gray-900",
    htmlFor: field.id
  }, label));
}

RadioField.propTypes = {
  id: PropTypes.string,
  name: PropTypes.string.isRequired,
  label: PropTypes.string,
  value: PropTypes.string,
  onChange: PropTypes.func,
  checked: PropTypes.bool
};

export { RadioField as default };
