import { jsxs as t, jsx as r, Fragment as K } from "react/jsx-runtime";
import { forwardRef as O, useRef as P, useCallback as Q, useEffect as U } from "react";
import { cx as n } from "../../utils/classNames.js";
import { useArrowTheme as W } from "../../hooks/useArrowTheme.js";
function X() {
  return /* @__PURE__ */ r(
    "svg",
    {
      role: "img",
      "aria-label": "error",
      width: "12",
      height: "12",
      viewBox: "0 0 24 24",
      fill: "currentColor",
      children: /* @__PURE__ */ r("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z" })
    }
  );
}
const Y = O(
  ({
    form: y,
    id: l,
    name: w,
    label: I,
    link: i,
    links: a,
    checked: v,
    defaultChecked: L,
    disabled: R = !1,
    inverse: j,
    required: x = !1,
    labelSize: h = "large",
    indeterminate: d = !1,
    invalid: z,
    errorMessage: E = "",
    labelledBy: p,
    linkDisabled: u = !1,
    hover: M = !1,
    pressed: A = !1,
    focused: f = !1,
    className: B,
    onChange: F,
    ...S
  }, o) => {
    const T = W(), V = j ?? T.inverse, b = P(null), c = E.trim(), G = h === "small", H = i !== void 0, k = G && ((a == null ? void 0 : a.length) ?? 0) > 0, _ = H || k, g = p || "label-" + l, m = l + "-error", C = [g, c ? m : ""].filter(Boolean).join(" ") || void 0, J = Q(
      (e) => {
        b.current = e, typeof o == "function" ? o(e) : o && (o.current = e);
      },
      [o]
    );
    U(() => {
      b.current && (b.current.indeterminate = d);
    }, [d]);
    const N = (e, s) => e.url ? /* @__PURE__ */ r(
      "a",
      {
        className: n("tdds-checkbox__link", {
          "force-focus": f
        }),
        href: e.url,
        onClick: e.onClick,
        "aria-describedby": C,
        "aria-disabled": u || void 0,
        children: e.text
      },
      s
    ) : /* @__PURE__ */ r(
      "button",
      {
        type: "button",
        className: n("tdds-checkbox__link", {
          "force-focus": f
        }),
        onClick: e.onClick,
        "aria-describedby": C,
        "aria-disabled": u || void 0,
        children: e.text
      },
      s
    );
    return /* @__PURE__ */ t(
      "div",
      {
        className: n("tdds-checkbox", B),
        "data-inverse": V ? "true" : void 0,
        "data-withlink": _ ? "true" : void 0,
        "data-size": h,
        "data-link-disabled": u ? "true" : void 0,
        children: [
          /* @__PURE__ */ t("div", { className: "tdds-checkbox__track", children: [
            /* @__PURE__ */ r(
              "input",
              {
                ref: J,
                "aria-describedby": c ? m : void 0,
                "aria-labelledby": p,
                "aria-disabled": R || void 0,
                "aria-checked": d ? "mixed" : void 0,
                "aria-invalid": z || c.length > 0 || void 0,
                role: d ? "checkbox" : void 0,
                className: n(
                  "tdds-checkbox__input",
                  "tdds:screen-reader-only",
                  {
                    "force-focus": !_ && f,
                    "force-hover": M,
                    "force-pressed": A
                  }
                ),
                form: y,
                id: l,
                name: w,
                type: "checkbox",
                checked: v,
                defaultChecked: v === void 0 ? L : void 0,
                required: x,
                onChange: F,
                ...S
              }
            ),
            /* @__PURE__ */ r(
              "label",
              {
                id: g,
                htmlFor: l,
                className: "tdds-checkbox__label",
                "data-size": i ? void 0 : h,
                children: /* @__PURE__ */ t("span", { className: "tdds-checkbox__label-text", children: [
                  I,
                  x ? /* @__PURE__ */ r("span", { "aria-hidden": "true", children: "*" }) : null
                ] })
              }
            )
          ] }),
          i ? N(i, "single-link") : null,
          k ? /* @__PURE__ */ r("ul", { className: "tdds-checkbox__links", role: "list", children: a == null ? void 0 : a.map((e, s) => /* @__PURE__ */ r("li", { role: "listitem", children: N(e, "multi-link-" + s) }, s)) }) : null,
          /* @__PURE__ */ r(
            "p",
            {
              id: m,
              className: "tdds-checkbox__error-message",
              "aria-hidden": !c || void 0,
              children: c ? /* @__PURE__ */ t(K, { children: [
                /* @__PURE__ */ r(X, {}),
                c
              ] }) : null
            }
          )
        ]
      }
    );
  }
);
Y.displayName = "Checkbox";
export {
  Y as Checkbox
};
//# sourceMappingURL=Checkbox.js.map
