import { jsxs as v, jsx as e } from "react/jsx-runtime";
import ne, { forwardRef as j, useCallback as D, useMemo as R } from "react";
import { f as S, g as A, b as H, h as E, i as K, j as ce, C as te, N as L } from "./core-BpghV7Ls.js";
const ie = j(
  ({
    label: r,
    helperText: p,
    error: i,
    required: N,
    disabled: c,
    readOnly: o,
    size: _ = "md",
    name: f,
    id: b,
    className: C,
    style: d,
    accessMode: x,
    displayStyle: k,
    value: s,
    onChange: n,
    onBlur: u,
    onKeyDown: g,
    placeholder: y,
    min: m,
    max: h,
    step: t = 1,
    precision: M,
    prefix: O,
    suffix: U,
    showStepper: F = !0,
    submitOnEnter: T,
    onSubmit: G,
    showKeyboardHints: J
  }, P) => {
    const w = S(x, b);
    if (w === "hidden")
      return null;
    w === "disabled" && (c = !0), w === "readOnly" && (o = !0);
    const { t: I } = A(), q = H(b), Q = E("input", k), V = K("input", k), $ = D(
      (l) => {
        let a = l;
        return m !== void 0 && (a = Math.max(m, a)), h !== void 0 && (a = Math.min(h, a)), M !== void 0 && (a = parseFloat(a.toFixed(M))), a;
      },
      [m, h, M]
    ), X = D(
      (l) => {
        const a = l.target.value;
        if (a === "") {
          n?.(null);
          return;
        }
        const W = parseFloat(a);
        isNaN(W) || n?.($(W));
      },
      [n, $]
    ), Y = D(() => {
      n?.($((s ?? 0) + t));
    }, [s, t, n, $]), Z = D(() => {
      n?.($((s ?? 0) - t));
    }, [s, t, n, $]), z = ce({
      enabled: T,
      onSubmit: G
    }), ee = D(
      (l) => {
        z(l), g?.(l);
      },
      [z, g]
    ), B = R(() => {
      const l = [];
      return T && l.push(te.submit), F && (l.push({ key: "ArrowUp", description: I("shortcuts.increment", "Increase value") }), l.push({ key: "ArrowDown", description: I("shortcuts.decrement", "Decrease value") })), l;
    }, [T, F, I]);
    return /* @__PURE__ */ v("div", { className: `nice-field ${C || ""}`, style: d, children: [
      r && /* @__PURE__ */ v(
        "label",
        {
          htmlFor: q,
          className: `nice-field__label ${N ? "nice-field__label--required" : ""}`,
          children: [
            r,
            J && B.length > 0 && /* @__PURE__ */ e(L, { shortcuts: B, size: "sm" })
          ]
        }
      ),
      /* @__PURE__ */ v(
        "div",
        {
          className: `nice-input nice-input--${_} nice-input--ds-${V} ${i ? "nice-input--error" : ""} ${c ? "nice-input--disabled" : ""} ${o ? "nice-input--readonly" : ""}`,
          style: Q,
          children: [
            O && /* @__PURE__ */ e("span", { className: "nice-input__icon", children: O }),
            F && !o && /* @__PURE__ */ e(
              "button",
              {
                type: "button",
                className: "nice-input__clear",
                onClick: Z,
                disabled: c,
                "aria-label": I("controls.decrement", "Decrement"),
                children: "−"
              }
            ),
            /* @__PURE__ */ e(
              "input",
              {
                ref: P,
                id: q,
                className: "nice-input__native",
                type: "number",
                name: f,
                value: s ?? "",
                placeholder: y,
                min: m,
                max: h,
                step: t,
                disabled: c,
                readOnly: o,
                "aria-invalid": !!i,
                onChange: X,
                onBlur: u,
                onKeyDown: ee
              }
            ),
            F && !o && /* @__PURE__ */ e(
              "button",
              {
                type: "button",
                className: "nice-input__clear",
                onClick: Y,
                disabled: c,
                "aria-label": I("controls.increment", "Increment"),
                children: "+"
              }
            ),
            U && /* @__PURE__ */ e("span", { className: "nice-input__icon", children: U })
          ]
        }
      ),
      i && /* @__PURE__ */ e("div", { className: "nice-field__error", role: "alert", children: i }),
      !i && p && /* @__PURE__ */ e("div", { className: "nice-field__helper", children: p })
    ] });
  }
);
ie.displayName = "NiceNumberInput";
const se = j(
  ({
    label: r,
    checked: p = !1,
    indeterminate: i = !1,
    onChange: N,
    disabled: c,
    size: o = "md",
    name: _,
    id: f,
    className: b,
    style: C,
    error: d,
    accessMode: x,
    displayStyle: k,
    showKeyboardHints: s
  }, n) => {
    const u = S(x, f);
    if (u === "hidden")
      return null;
    (u === "disabled" || u === "readOnly") && (c = !0);
    const { t: g } = A(), y = H(f);
    K("toggle", k);
    const m = R(
      () => [{ key: "Space", description: g("shortcuts.toggle", "Toggle") }],
      [g]
    ), h = ne.useCallback(
      (t) => {
        t && (t.indeterminate = i), typeof n == "function" ? n(t) : n && (n.current = t);
      },
      [i, n]
    );
    return /* @__PURE__ */ v("div", { className: b, style: C, children: [
      /* @__PURE__ */ v(
        "label",
        {
          className: `nice-checkbox ${o !== "md" ? `nice-checkbox--${o}` : ""} ${c ? "nice-checkbox--disabled" : ""}`,
          htmlFor: y,
          children: [
            /* @__PURE__ */ e(
              "input",
              {
                ref: h,
                id: y,
                type: "checkbox",
                className: "nice-checkbox__input",
                name: _,
                checked: p,
                disabled: c,
                "aria-invalid": !!d,
                onChange: (t) => N?.(t.target.checked)
              }
            ),
            /* @__PURE__ */ e("span", { className: "nice-checkbox__box", children: /* @__PURE__ */ e(
              "svg",
              {
                viewBox: "0 0 12 12",
                fill: "none",
                stroke: "currentColor",
                strokeWidth: "2",
                strokeLinecap: "round",
                strokeLinejoin: "round",
                children: i ? /* @__PURE__ */ e("line", { x1: "2", y1: "6", x2: "10", y2: "6" }) : /* @__PURE__ */ e("polyline", { points: "2 6 5 9 10 3" })
              }
            ) }),
            r && /* @__PURE__ */ e("span", { children: r }),
            s && /* @__PURE__ */ e(L, { shortcuts: m, size: "sm" })
          ]
        }
      ),
      d && /* @__PURE__ */ e("div", { className: "nice-field__error", role: "alert", children: d })
    ] });
  }
);
se.displayName = "NiceCheckbox";
const le = j(
  ({
    label: r,
    checked: p = !1,
    onChange: i,
    disabled: N,
    size: c = "md",
    name: o,
    id: _,
    className: f,
    style: b,
    accessMode: C,
    displayStyle: d,
    showKeyboardHints: x
  }, k) => {
    const s = S(C, _);
    if (s === "hidden")
      return null;
    (s === "disabled" || s === "readOnly") && (N = !0);
    const { t: n } = A(), u = H(_), g = E("toggle", d), y = K("toggle", d), m = R(
      () => [{ key: "Space", description: n("shortcuts.toggle", "Toggle on/off") }],
      [n]
    );
    return /* @__PURE__ */ v(
      "label",
      {
        className: `nice-toggle nice-toggle--ds-${y} ${c !== "md" ? `nice-toggle--${c}` : ""} ${N ? "nice-toggle--disabled" : ""} ${f || ""}`,
        htmlFor: u,
        style: { ...g, ...b },
        children: [
          /* @__PURE__ */ e(
            "input",
            {
              ref: k,
              id: u,
              type: "checkbox",
              className: "nice-toggle__input",
              name: o,
              checked: p,
              disabled: N,
              role: "switch",
              "aria-checked": p,
              onChange: (h) => i?.(h.target.checked)
            }
          ),
          /* @__PURE__ */ e("span", { className: "nice-toggle__track", children: /* @__PURE__ */ e("span", { className: "nice-toggle__thumb" }) }),
          r && /* @__PURE__ */ e("span", { children: r }),
          x && /* @__PURE__ */ e(L, { shortcuts: m, size: "sm" })
        ]
      }
    );
  }
);
le.displayName = "NiceToggle";
export {
  se as N,
  ie as a,
  le as b
};
