"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const React = require("react");
const classNames = require("../_util/classNames.js");
const is = require("../_util/is.js");
const radio = require("./radio.js");
const index = require("../ConfigProvider/index.js");
const useMergeValue = require("../_util/hooks/useMergeValue.js");
const useMergeProps = require("../_util/hooks/useMergeProps.js");
const pick = require("../_util/pick.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
var RadioGroupContext = React.createContext({
  type: "radio"
});
var defaultProps = {
  type: "radio",
  mode: "outline",
  direction: "horizontal"
};
function Group(baseProps) {
  var _a;
  var _b = React.useContext(index.ConfigContext), getPrefixCls = _b.getPrefixCls, ctxSize = _b.size, componentConfig = _b.componentConfig, rtl = _b.rtl;
  var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig["Radio.Group"]);
  var style = props.style, className = props.className, name = props.name, children = props.children, direction = props.direction, type = props.type, mode = props.mode, options = props.options, disabled = props.disabled;
  var _c = __read(useMergeValue(void 0, {
    defaultValue: props.defaultValue,
    value: props.value
  }), 2), value = _c[0], setValue = _c[1];
  var size = props.size || ctxSize;
  var prefixCls = getPrefixCls("radio");
  var classNames$1 = classNames(prefixCls + "-group", (_a = {}, _a[prefixCls + "-group-type-button"] = type !== "radio", _a[prefixCls + "-size-" + size] = !!size, _a[prefixCls + "-mode-" + mode] = !!mode, _a[prefixCls + "-group-disabled"] = disabled, _a[prefixCls + "-group-direction-vertical"] = direction === "vertical", _a[prefixCls + "-group-rtl"] = rtl, _a), className);
  var onChangeValue = function(v, event) {
    var onChange = props.onChange;
    if (v !== value) {
      if (!("value" in props)) {
        setValue(v);
      }
      onChange && onChange(v, event);
    }
  };
  var contextProp = {
    onChangeValue,
    type,
    value,
    disabled,
    group: true,
    name
  };
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(RadioGroupContext.Provider, {
    value: contextProp,
    children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
      ...__assign({
        className: classNames$1,
        style
      }, pick.pickDataAttributes(props)),
      children: options && is.isArray(options) ? options.map(function(option, index2) {
        if (is.isObject(option)) {
          return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(radio, {
            disabled: disabled || option.disabled,
            value: option.value,
            children: option.label
          }, option.value);
        }
        return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(radio, {
          value: option,
          disabled,
          children: option
        }, index2);
      }) : children
    })
  });
}
Group.displayName = "RadioGroup";
exports.RadioGroupContext = RadioGroupContext;
exports.default = Group;
//# sourceMappingURL=group.js.map
