import { jsxs as F, jsx as r } from "react/jsx-runtime";
import { useRef as H, useEffect as K } from "react";
import { noop as k } from "es-toolkit/function";
import p from "../../utils/classNames.js";
import { CheckboxIcon as P } from "./CheckboxIcon.js";
const S = 16, x = "vertical", V = "horizontal", I = (l) => {
  const {
    checked: L,
    children: o,
    className: d,
    custom: m = !1,
    defaultChecked: g,
    disabled: c = !1,
    error: N = !1,
    icon: s = "",
    iconLabelPosition: E = x,
    iconSize: _ = S,
    id: f = l.name,
    indeterminate: a = !1,
    inline: A = !1,
    inputRef: O,
    label: R,
    name: D,
    onChange: h = k,
    onClick: u = k,
    required: T = !1,
    right: y,
    size: C,
    tabIndex: B = 0,
    ...w
  } = l, n = H(null);
  K(() => {
    const e = n.current?.firstChild;
    e && (e.indeterminate = a);
  }, [a, n.current]);
  const z = (e) => {
    switch (e.key) {
      case " ":
        b(e);
        break;
      case "Enter":
        b(e);
        break;
    }
  }, b = (e) => {
    if (e.preventDefault(), c)
      return;
    const t = n.current?.firstChild;
    t.indeterminate && (t.indeterminate = !1), t.checked = !t.checked, u(e), h(e);
  }, i = R || o, Z = p(
    "checkbox",
    A && "checkbox-inline",
    C === "large" && "checkbox-large",
    y && "checkbox-right",
    c && "disabled",
    d
  ), j = p(
    N && "error",
    C === "large" && "large",
    a && "indeterminate",
    d
  );
  return /* @__PURE__ */ F(
    "label",
    {
      ...w,
      className: Z,
      tabIndex: B,
      htmlFor: f,
      onKeyDown: z,
      ref: n,
      children: [
        /* @__PURE__ */ r(
          "input",
          {
            id: f,
            name: D,
            type: "checkbox",
            checked: L,
            required: T,
            defaultChecked: g,
            disabled: c,
            className: j,
            onClick: u,
            onChange: h,
            ref: O
          }
        ),
        !!s && /* @__PURE__ */ r(P, { icon: s, iconSize: _, iconLabelPosition: E, text: i }),
        !s && !m && /* @__PURE__ */ r("span", { className: "checkbox-text", children: i && /* @__PURE__ */ r("span", { children: i }) }),
        m && o && o
      ]
    }
  );
};
I.ICON_LABEL_VERTICAL = x;
I.ICON_LABEL_HORIZONTAL = V;
export {
  I as default
};
//# sourceMappingURL=Checkbox.js.map
