import { jsxs as v, jsx as t } from "react/jsx-runtime";
import * as d from "react";
import { forwardRef as z } from "react";
import { F as B } from "./field-error-text-CBSX8dGx.mjs";
import { F as O } from "./field-helper-text-C5ee4SFV.mjs";
import { b as R } from "./icon.es-CZcKxTaM.mjs";
import { l as j } from "./checkmark-bold.es-CV3e_t3E.mjs";
import { L as q } from "./label-7sJe5-pX.mjs";
import { a as A } from "./paragraph-DNtj7OLr.mjs";
import { u as K } from "./index-DLcqcWxM.mjs";
import { c as X } from "./index-DOfn3ixy.mjs";
import { u as Z, c as N, a as G } from "./index-tyLV0iiH.mjs";
import { u as J } from "./index-DPxjTK4w.mjs";
import { P as Q } from "./index-C1AXAWlO.mjs";
import { P as S } from "./index-CCNZ9uWB.mjs";
import { c as U } from "./bind-CU-R61T-.mjs";
const V = {
  name: "minus-bold",
  svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M3 12c0-1.105.711-2 1.588-2h14.824c.877 0 1.588.895 1.588 2s-.711 2-1.588 2H4.588C3.711 14 3 13.105 3 12Z" clip-rule="evenodd"/></svg>',
  keywords: ["minus-bold"],
  category: "utility"
};
var P = "Checkbox", [W] = X(P), [Y, I] = W(P), F = d.forwardRef(
  (e, s) => {
    const {
      __scopeCheckbox: r,
      name: u,
      checked: p,
      defaultChecked: o,
      required: h,
      disabled: a,
      value: c = "on",
      onCheckedChange: k,
      form: i,
      ...x
    } = e, [f, y] = d.useState(null), g = K(s, (n) => y(n)), w = d.useRef(!1), $ = f ? i || !!f.closest("form") : !0, [_ = !1, E] = Z({
      prop: p,
      defaultProp: o,
      onChange: k
    }), M = d.useRef(_);
    return d.useEffect(() => {
      const n = f?.form;
      if (n) {
        const C = () => E(M.current);
        return n.addEventListener("reset", C), () => n.removeEventListener("reset", C);
      }
    }, [f, E]), /* @__PURE__ */ v(Y, { scope: r, state: _, disabled: a, children: [
      /* @__PURE__ */ t(
        S.button,
        {
          type: "button",
          role: "checkbox",
          "aria-checked": b(_) ? "mixed" : _,
          "aria-required": h,
          "data-state": L(_),
          "data-disabled": a ? "" : void 0,
          disabled: a,
          value: c,
          ...x,
          ref: g,
          onKeyDown: N(e.onKeyDown, (n) => {
            n.key === "Enter" && n.preventDefault();
          }),
          onClick: N(e.onClick, (n) => {
            E((C) => b(C) ? !0 : !C), $ && (w.current = n.isPropagationStopped(), w.current || n.stopPropagation());
          })
        }
      ),
      $ && /* @__PURE__ */ t(
        T,
        {
          control: f,
          bubbles: !w.current,
          name: u,
          value: c,
          checked: _,
          required: h,
          disabled: a,
          form: i,
          style: { transform: "translateX(-100%)" },
          defaultChecked: b(o) ? !1 : o
        }
      )
    ] });
  }
);
F.displayName = P;
var D = "CheckboxIndicator", H = d.forwardRef(
  (e, s) => {
    const { __scopeCheckbox: r, forceMount: u, ...p } = e, o = I(D, r);
    return /* @__PURE__ */ t(Q, { present: u || b(o.state) || o.state === !0, children: /* @__PURE__ */ t(
      S.span,
      {
        "data-state": L(o.state),
        "data-disabled": o.disabled ? "" : void 0,
        ...p,
        ref: s,
        style: { pointerEvents: "none", ...e.style }
      }
    ) });
  }
);
H.displayName = D;
var T = (e) => {
  const { control: s, checked: r, bubbles: u = !0, defaultChecked: p, ...o } = e, h = d.useRef(null), a = G(r), c = J(s);
  d.useEffect(() => {
    const i = h.current, x = window.HTMLInputElement.prototype, y = Object.getOwnPropertyDescriptor(x, "checked").set;
    if (a !== r && y) {
      const g = new Event("click", { bubbles: u });
      i.indeterminate = b(r), y.call(i, b(r) ? !1 : r), i.dispatchEvent(g);
    }
  }, [a, r, u]);
  const k = d.useRef(b(r) ? !1 : r);
  return /* @__PURE__ */ t(
    "input",
    {
      type: "checkbox",
      "aria-hidden": !0,
      defaultChecked: p ?? k.current,
      ...o,
      tabIndex: -1,
      ref: h,
      style: {
        ...e.style,
        ...c,
        position: "absolute",
        pointerEvents: "none",
        opacity: 0,
        margin: 0
      }
    }
  );
};
function b(e) {
  return e === "indeterminate";
}
function L(e) {
  return b(e) ? "indeterminate" : e ? "checked" : "unchecked";
}
var ee = F, re = H;
const te = {
  "purpur-checkbox": "_purpur-checkbox_1lc8s_1",
  "purpur-checkbox__box": "_purpur-checkbox__box_1lc8s_7",
  "purpur-checkbox--error": "_purpur-checkbox--error_1lc8s_16",
  "purpur-checkbox--error-checkbox": "_purpur-checkbox--error-checkbox_1lc8s_16",
  "purpur-checkbox__indicator": "_purpur-checkbox__indicator_1lc8s_59",
  "purpur-checkbox__label-container": "_purpur-checkbox__label-container_1lc8s_70",
  "purpur-checkbox__wrapper": "_purpur-checkbox__wrapper_1lc8s_76",
  "purpur-checkbox__container": "_purpur-checkbox__container_1lc8s_82"
}, m = U.bind(te), xe = ["indeterminate", !0, !1], l = "purpur-checkbox", oe = z(
  ({
    ["data-testid"]: e,
    checked: s,
    className: r,
    error: u = !1,
    errorText: p,
    label: o,
    helperText: h,
    onChange: a,
    ...c
  }, k) => {
    const i = p && !s, x = u && !s;
    return /* @__PURE__ */ v("div", { className: m([`${l}__wrapper`, r]), children: [
      /* @__PURE__ */ v("div", { className: m([`${l}__container`, r]), children: [
        /* @__PURE__ */ t(
          ee,
          {
            ...c,
            checked: s,
            className: m([
              l,
              {
                [`${l}--error`]: i,
                [`${l}--error-checkbox`]: x
              }
            ]),
            "data-testid": e,
            onCheckedChange: a,
            ref: k,
            children: /* @__PURE__ */ t("span", { className: m(`${l}__box`), children: /* @__PURE__ */ t(re, { className: m(`${l}__indicator`), children: s === "indeterminate" ? /* @__PURE__ */ t(
              R,
              {
                "data-testid": e && `${e}-checked-icon`,
                size: "xs",
                svg: V
              }
            ) : /* @__PURE__ */ t(
              R,
              {
                "data-testid": e && `${e}-indeterminate-icon`,
                size: "xs",
                svg: j
              }
            ) }) })
          }
        ),
        /* @__PURE__ */ v("span", { className: m(`${l}__label-container`), children: [
          o && /* @__PURE__ */ t(
            q,
            {
              htmlFor: c.id,
              "data-testid": e && `${e}-label`,
              disabled: c.disabled,
              children: /* @__PURE__ */ v(A, { variant: "paragraph-100", disabled: c.disabled, children: [
                c.required && /* @__PURE__ */ t("span", { "aria-hidden": !0, children: "* " }),
                o
              ] })
            }
          ),
          h && /* @__PURE__ */ t(
            O,
            {
              className: m(`${l}__helper`),
              "data-testid": e && `${e}-helper-text`,
              disabled: c.disabled,
              id: `${c.id}-helper-text`,
              children: h
            }
          )
        ] })
      ] }),
      i && /* @__PURE__ */ t(B, { "data-testid": e && `${e}-error-text`, children: p })
    ] });
  }
);
oe.displayName = "Checkbox";
export {
  oe as C,
  xe as c
};
//# sourceMappingURL=checkbox-LYzMiXu7.mjs.map
