import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import { forwardRef, useState, Children, cloneElement } from 'react';
import classnames from 'classnames';
import Label from './Label.js';
import { u as useId } from './useId-Jj9hXm-g.js';
import 'react-router-dom';
import '@bigbinary/neeto-hotkeys';
import './overlayManager.js';
import { h as hyphenize } from './index-QWVp_Xt6.js';
import 'qs';
import { jsxs, jsx } from 'react/jsx-runtime';
import '@bigbinary/neeto-icons/Help';
import './Button.js';
import './Spinner.js';
import './Tooltip.js';
import '@tippyjs/react';
import 'tippy.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '@bigbinary/neeto-cist';
import 'ramda';
import './index-DyUNP5G9.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'dayjs';
import 'dayjs/plugin/localeData';
import 'dayjs/plugin/utc';
import 'dayjs/plugin/weekday';
import 'dayjs/plugin/weekOfYear';
import 'i18next';
import './usePrefersReducedMotion-n4ZJtExQ.js';
import './Popover.js';
import './Typography.js';
import './en-Dmu3B4Vs.js';

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(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__*/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(_ref, _excluded$1);
  var id = useId(otherProps.id);
  return /*#__PURE__*/jsxs("div", {
    className: classnames(["neeto-ui-radio__item", className]),
    children: [/*#__PURE__*/jsx("input", _objectSpread$1({
      id: id,
      name: name,
      ref: ref,
      className: "neeto-ui-radio",
      "data-testid": dataTestid || "".concat(hyphenize(label), "-radio-input"),
      type: "radio"
    }, otherProps)), label && /*#__PURE__*/jsx(Label, _objectSpread$1(_objectSpread$1({
      "data-testid": dataTestid || "".concat(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(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(_ref, _excluded);
  var _useState = useState(""),
    _useState2 = _slicedToArray(_useState, 2),
    internalValue = _useState2[0],
    setInternalValue = _useState2[1];
  var id = 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__*/jsxs("div", {
    className: classnames(["neeto-ui-radio__wrapper", className]),
    children: [label && /*#__PURE__*/jsx(Label, _objectSpread(_objectSpread({
      className: "neeto-ui-radio__label",
      id: finalLabelId
    }, labelProps), {}, {
      children: label
    })), /*#__PURE__*/jsx("div", {
      "aria-describedby": error ? errorId : undefined,
      "aria-invalid": !!error,
      "aria-labelledby": finalLabelId,
      role: "radiogroup",
      className: classnames(["neeto-ui-radio__container"], _defineProperty({
        "neeto-ui-radio__container--stacked": stacked,
        "neeto-ui-radio__container--error": error
      }, containerClassName, containerClassName)),
      children: Children.map(children, function (child) {
        var _child$props$checked, _ref2, _child$props$onChange;
        return /*#__PURE__*/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__*/jsx("p", {
      className: "neeto-ui-radio-input__error",
      "data-testid": "".concat(hyphenize(label), "-radio-input-error"),
      id: errorId,
      children: error
    })]
  });
};
Radio.Item = Item;

export { Radio as default };
//# sourceMappingURL=Radio.js.map
