import h from "../../Checkbox.js";
import { jsx as o, jsxs as $ } from "react/jsx-runtime";
import j, { useState as G, useCallback as N, useMemo as S } from "react";
import { CheckboxGroupProvider as _ } from "../../context/CheckboxGroupContext.js";
import { c as x } from "../../../../index-BtlgVD4m.js";
import w from "../../../box/Box.js";
const q = ({
  options: u,
  value: i,
  onChange: s,
  isDisabled: t = !1,
  defaultValue: C,
  children: d,
  className: v,
  spacing: b = "2",
  ...f
}) => {
  const [k, y] = G(C || []), m = i !== void 0, l = m ? i : k, n = N(
    (e, r) => {
      const c = r ? [...l, e] : l.filter((a) => a !== e);
      m || y(c), s == null || s(c);
    },
    [l, m, s]
  ), g = S(
    () => ({
      value: l,
      disabled: t,
      toggleValue: n,
      isSelected: (e) => l.some((r) => r === e)
    }),
    [l, t, n]
  ), p = u && u.length > 0, V = j.Children.count(d) > 0;
  return p && !V ? /* @__PURE__ */ o(
    "div",
    {
      className: x(
        `flex flex-col gap-[var(--spacing-${b})]`,
        // Stack checkboxes vertically with spacing
        t && "opacity-[var(--opacity-opacity-50)]",
        // Visual disabled state
        v
      ),
      ...f,
      children: u.map((e, r) => {
        const c = l.some((a) => a === e.value);
        return /* @__PURE__ */ o(
          h,
          {
            label: e.label,
            value: c,
            disabled: t,
            onChange: (a) => n(e.value, a)
          },
          e.value ?? `option-${r}`
        );
      })
    }
  ) : /* @__PURE__ */ o(_, { value: g, children: /* @__PURE__ */ $(
    "div",
    {
      className: x(
        t && "opacity-[var(--opacity-opacity-50)]",
        // Visual disabled state for children pattern
        v
      ),
      ...f,
      children: [
        d,
        p && /* @__PURE__ */ o(w, { className: "flex flex-col gap-[var(--spacing-2)]", children: u.map((e, r) => {
          const c = l.some((a) => a === e.value);
          return /* @__PURE__ */ o(
            h,
            {
              label: e.label,
              value: c,
              disabled: t,
              onChange: (a) => n(e.value, a)
            },
            e.value ?? `option-${r}`
          );
        }) })
      ]
    }
  ) });
};
export {
  q as default
};
//# sourceMappingURL=CheckboxGroup.js.map
