import { createContext, useContext } from "react";
import cs from "../_util/classNames.js";
import { isArray, isObject } from "../_util/is.js";
import Radio from "./radio.js";
import { ConfigContext } from "../ConfigProvider/index.js";
import useMergeValue from "../_util/hooks/useMergeValue.js";
import useMergeProps from "../_util/hooks/useMergeProps.js";
import { pickDataAttributes } from "../_util/pick.js";
import { jsx } from "../../../../../../@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 = createContext({
  type: "radio"
});
var defaultProps = {
  type: "radio",
  mode: "outline",
  direction: "horizontal"
};
function Group(baseProps) {
  var _a;
  var _b = useContext(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 = cs(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__ */ jsx(RadioGroupContext.Provider, {
    value: contextProp,
    children: /* @__PURE__ */ jsx("div", {
      ...__assign({
        className: classNames,
        style
      }, pickDataAttributes(props)),
      children: options && isArray(options) ? options.map(function(option, index) {
        if (isObject(option)) {
          return /* @__PURE__ */ jsx(Radio, {
            disabled: disabled || option.disabled,
            value: option.value,
            children: option.label
          }, option.value);
        }
        return /* @__PURE__ */ jsx(Radio, {
          value: option,
          disabled,
          children: option
        }, index);
      }) : children
    })
  });
}
Group.displayName = "RadioGroup";
export {
  RadioGroupContext,
  Group as default
};
//# sourceMappingURL=group.js.map
