"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.RadioGroup = void 0;
var Ariakit = _interopRequireWildcard(require("@ariakit/react"));
var _element = require("@wordpress/element");
var _i18n = require("@wordpress/i18n");
var _buttonGroup = _interopRequireDefault(require("../button-group"));
var _context = require("./context");
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
 * External dependencies
 */

/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function UnforwardedRadioGroup({
  label,
  checked,
  defaultChecked,
  disabled,
  onChange,
  children,
  ...props
}, ref) {
  const radioStore = Ariakit.useRadioStore({
    value: checked,
    defaultValue: defaultChecked,
    setValue: newValue => {
      onChange?.(newValue !== null && newValue !== void 0 ? newValue : undefined);
    },
    rtl: (0, _i18n.isRTL)()
  });
  const contextValue = (0, _element.useMemo)(() => ({
    store: radioStore,
    disabled
  }), [radioStore, disabled]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_context.RadioGroupContext.Provider, {
    value: contextValue,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Ariakit.RadioGroup, {
      store: radioStore,
      render: /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttonGroup.default, {
        children: children
      }),
      "aria-label": label,
      ref: ref,
      ...props
    })
  });
}

/**
 * @deprecated Use `RadioControl` or `ToggleGroupControl` instead.
 */
const RadioGroup = exports.RadioGroup = (0, _element.forwardRef)(UnforwardedRadioGroup);
var _default = exports.default = RadioGroup;
//# sourceMappingURL=index.js.map