'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var classnames = require('classnames');
var Label = require('./Label.js');
var useId = require('./useId-DXHUzdxd.js');
require('react-router-dom');
require('@bigbinary/neeto-hotkeys');
require('./overlayManager.js');
var index = require('./index-CNZKW5X0.js');
require('qs');
var jsxRuntime = require('react/jsx-runtime');
require('@bigbinary/neeto-icons/Help');
require('./Button.js');
require('./Spinner.js');
require('./Tooltip.js');
require('@tippyjs/react');
require('tippy.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('@bigbinary/neeto-cist');
require('ramda');
require('./index-BgzkP01c.js');
require('@babel/runtime/helpers/toConsumableArray');
require('dayjs');
require('dayjs/plugin/localeData');
require('dayjs/plugin/utc');
require('dayjs/plugin/weekday');
require('dayjs/plugin/weekOfYear');
require('i18next');
require('./usePrefersReducedMotion-D2Ck84HM.js');
require('./Popover.js');
require('./Typography.js');
require('./en-B1i-pQJm.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

var _excluded$1 = ["name", "label", "className", "labelProps", "dataTestid"];
function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Item = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
  var _ref$name = _ref.name,
    name = _ref$name === void 0 ? "" : _ref$name,
    _ref$label = _ref.label,
    label = _ref$label === void 0 ? "" : _ref$label,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    labelProps = _ref.labelProps,
    _ref$dataTestid = _ref.dataTestid,
    dataTestid = _ref$dataTestid === void 0 ? "" : _ref$dataTestid,
    otherProps = _objectWithoutProperties__default.default(_ref, _excluded$1);
  var id = useId.useId(otherProps.id);
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: classnames__default.default(["neeto-ui-radio__item", className]),
    children: [/*#__PURE__*/jsxRuntime.jsx("input", _objectSpread$1({
      id: id,
      name: name,
      ref: ref,
      className: "neeto-ui-radio",
      "data-testid": dataTestid || "".concat(index.hyphenize(label), "-radio-input"),
      type: "radio"
    }, otherProps)), label && /*#__PURE__*/jsxRuntime.jsx(Label, _objectSpread$1(_objectSpread$1({
      "data-testid": dataTestid || "".concat(index.hyphenize(label), "-radio-label"),
      htmlFor: id
    }, labelProps), {}, {
      children: label
    }))]
  });
});
Item.displayName = "Radio.Item";

var _excluded = ["label", "children", "stacked", "className", "containerClassName", "error", "onChange", "labelProps"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Radio = function Radio(_ref) {
  var _ref$label = _ref.label,
    label = _ref$label === void 0 ? "" : _ref$label,
    children = _ref.children,
    _ref$stacked = _ref.stacked,
    stacked = _ref$stacked === void 0 ? false : _ref$stacked,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    _ref$containerClassNa = _ref.containerClassName,
    containerClassName = _ref$containerClassNa === void 0 ? "" : _ref$containerClassNa,
    _ref$error = _ref.error,
    error = _ref$error === void 0 ? "" : _ref$error,
    onChange = _ref.onChange,
    labelProps = _ref.labelProps,
    props = _objectWithoutProperties__default.default(_ref, _excluded);
  var _useState = React.useState(""),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    internalValue = _useState2[0],
    setInternalValue = _useState2[1];
  var id = useId.useId(props.id);
  var errorId = "error_".concat(id);
  var labelId = label ? "label_".concat(id) : undefined;
  var finalLabelId = label ? (labelProps === null || labelProps === void 0 ? void 0 : labelProps.id) || labelId : undefined;
  var internalOnChange = function internalOnChange(e) {
    return setInternalValue(e.target.value);
  };
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: classnames__default.default(["neeto-ui-radio__wrapper", className]),
    children: [label && /*#__PURE__*/jsxRuntime.jsx(Label, _objectSpread(_objectSpread({
      className: "neeto-ui-radio__label",
      id: finalLabelId
    }, labelProps), {}, {
      children: label
    })), /*#__PURE__*/jsxRuntime.jsx("div", {
      "aria-describedby": error ? errorId : undefined,
      "aria-invalid": !!error,
      "aria-labelledby": finalLabelId,
      role: "radiogroup",
      className: classnames__default.default(["neeto-ui-radio__container"], _defineProperty__default.default({
        "neeto-ui-radio__container--stacked": stacked,
        "neeto-ui-radio__container--error": error
      }, containerClassName, containerClassName)),
      children: React.Children.map(children, function (child) {
        var _child$props$checked, _ref2, _child$props$onChange;
        return /*#__PURE__*/React.cloneElement(child, _objectSpread(_objectSpread(_objectSpread({}, child.props), props), {}, {
          value: child.props.value,
          checked: (_child$props$checked = child.props.checked) !== null && _child$props$checked !== void 0 ? _child$props$checked : [internalValue, props.value].includes(child.props.value),
          onChange: (_ref2 = (_child$props$onChange = child.props.onChange) !== null && _child$props$onChange !== void 0 ? _child$props$onChange : onChange) !== null && _ref2 !== void 0 ? _ref2 : internalOnChange
        }));
      })
    }), !!error && /*#__PURE__*/jsxRuntime.jsx("p", {
      className: "neeto-ui-radio-input__error",
      "data-testid": "".concat(index.hyphenize(label), "-radio-input-error"),
      id: errorId,
      children: error
    })]
  });
};
Radio.Item = Item;

module.exports = Radio;
//# sourceMappingURL=Radio.js.map
