import h from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import * as s from "react";
import M from "../../../classnames/index.mjs";
import D from "../../../rc-util/es/omit.mjs";
import "../config-provider/index.mjs";
import F from "../config-provider/hooks/useCSSVarCls.mjs";
import H from "./Checkbox.mjs";
import J from "./GroupContext.mjs";
import K from "./style/index.mjs";
import { ConfigContext as L } from "../config-provider/context.mjs";
var Q = globalThis && globalThis.__rest || function(r, i) {
  var c = {};
  for (var t in r)
    Object.prototype.hasOwnProperty.call(r, t) && i.indexOf(t) < 0 && (c[t] = r[t]);
  if (r != null && typeof Object.getOwnPropertySymbols == "function")
    for (var l = 0, t = Object.getOwnPropertySymbols(r); l < t.length; l++)
      i.indexOf(t[l]) < 0 && Object.prototype.propertyIsEnumerable.call(r, t[l]) && (c[t[l]] = r[t[l]]);
  return c;
};
const U = (r, i) => {
  const {
    defaultValue: c,
    children: t,
    options: l = [],
    prefixCls: y,
    className: O,
    rootClassName: S,
    style: V,
    onChange: m
  } = r, a = Q(r, ["defaultValue", "children", "options", "prefixCls", "className", "rootClassName", "style", "onChange"]), {
    getPrefixCls: P,
    direction: N
  } = s.useContext(L), [u, b] = s.useState(a.value || c || []), [I, g] = s.useState([]);
  s.useEffect(() => {
    "value" in a && b(a.value || []);
  }, [a.value]);
  const f = s.useMemo(() => l.map((e) => typeof e == "string" || typeof e == "number" ? {
    label: e,
    value: e
  } : e), [l]), w = (e) => {
    g((o) => o.filter((n) => n !== e));
  }, j = (e) => {
    g((o) => [].concat(h(o), [e]));
  }, k = (e) => {
    const o = u.indexOf(e.value), n = h(u);
    o === -1 ? n.push(e.value) : n.splice(o, 1), "value" in a || b(n), m == null || m(n.filter((v) => I.includes(v)).sort((v, T) => {
      const z = f.findIndex((C) => C.value === v), B = f.findIndex((C) => C.value === T);
      return z - B;
    }));
  }, d = P("checkbox", y), p = `${d}-group`, x = F(d), [E, _, G] = K(d, x), R = D(a, ["value", "disabled"]), $ = l.length ? f.map((e) => /* @__PURE__ */ s.createElement(H, {
    prefixCls: d,
    key: e.value.toString(),
    disabled: "disabled" in e ? e.disabled : a.disabled,
    value: e.value,
    checked: u.includes(e.value),
    onChange: e.onChange,
    className: `${p}-item`,
    style: e.style,
    title: e.title,
    id: e.id,
    required: e.required
  }, e.label)) : t, q = {
    toggleOption: k,
    value: u,
    disabled: a.disabled,
    name: a.name,
    // https://github.com/ant-design/ant-design/issues/16376
    registerValue: j,
    cancelValue: w
  }, A = M(p, {
    [`${p}-rtl`]: N === "rtl"
  }, O, S, G, x, _);
  return E(/* @__PURE__ */ s.createElement("div", Object.assign({
    className: A,
    style: V
  }, R, {
    ref: i
  }), /* @__PURE__ */ s.createElement(J.Provider, {
    value: q
  }, $)));
}, W = /* @__PURE__ */ s.forwardRef(U), oe = /* @__PURE__ */ s.memo(W);
export {
  J as GroupContext,
  oe as default
};
