import { jsxs as N, jsx as t } from "react/jsx-runtime";
import { useId as I, useCallback as j, isValidElement as G } from "react";
import L from "./hooks/useCheckboxGroupContext.js";
import r from "../box/Box.js";
import z from "./components/checkbox-indicator/CheckboxIndicator.js";
import C from "../label/Label.js";
import { c as h } from "../../index-BtlgVD4m.js";
import D from "../text/Text.js";
import E from "../error-message/ErrorMessage.js";
const H = ({ label: g, description: o, disabled: f, errorMessage: p, onChange: i, value: e, children: y, ...u }) => {
  const n = I(), x = `${n}-label`, a = L(), l = !!a && e !== void 0, v = typeof e == "boolean" ? e : l ? a.isSelected(e) : e, s = l ? f || a.disabled : f, c = y || g, k = j(
    (b) => {
      l && e !== void 0 ? a.toggleValue(e, b) : i == null || i(b);
    },
    [l, e, a, i]
  ), d = o && (o == null ? void 0 : o.trim()) !== "", m = typeof c == "string" ? c.trim() !== "" : G(c);
  return /* @__PURE__ */ N(
    r,
    {
      className: h(
        "relative",
        "flex items-start leading-none gap-x-[var(--spacing-2)] gap-y-[var(--spacing-1-5)]",
        m && d && "grid grid-flow-col grid-rows-2"
      ),
      children: [
        /* @__PURE__ */ t(r, { className: "flex items-start leading-none", children: /* @__PURE__ */ t(
          z,
          {
            id: n,
            disabled: s,
            checked: v,
            onChange: k,
            ...s && m ? { "aria-labelledby": x } : {},
            ...u
          }
        ) }),
        d && m && /* @__PURE__ */ t(r, { className: "empty-cell" }),
        m && /* @__PURE__ */ t(r, { className: "flex items-start leading-none", children: /* @__PURE__ */ t(
          C,
          {
            id: s ? x : void 0,
            htmlFor: s ? void 0 : n,
            className: h(
              s ? "cursor-default" : "cursor-pointer",
              "text-[length:var(--typography-base-sizes-small-font-size)]",
              "leading-[var(--height-h-4)]",
              s && "opacity-[var(--opacity-opacity-70)]",
              !!p && "text-[var(--base-danger-text)]"
            ),
            children: c
          }
        ) }),
        d && /* @__PURE__ */ t(r, { className: "flex justify-start", children: /* @__PURE__ */ t(D, { type: "muted", children: o }) }),
        /* @__PURE__ */ t(E, { message: p })
      ]
    }
  );
};
export {
  H as default
};
//# sourceMappingURL=Checkbox.js.map
