import { jsx as l, jsxs as b, Fragment as J } from "react/jsx-runtime";
import { forwardRef as Q, useRef as Y, useState as Z } from "react";
import { noop as ee } from "es-toolkit/function";
import x from "../../utils/classNames.js";
import re from "../../hooks/useAfterMount.js";
const ne = 3, P = 0, se = 1, te = 0, oe = Number.MAX_VALUE, ae = [
  "0",
  "1",
  "2",
  "3",
  "4",
  "5",
  "6",
  "7",
  "8",
  "9",
  ".",
  ",",
  "-",
  "Backspace",
  "Tab",
  "ArrowLeft",
  "ArrowRight",
  "ArrowDown",
  "ArrowUp"
], C = (r, n, s, u, y) => r === void 0 && (u || y) ? "" : M(Number(r), n, s) || P, M = (r, n, s) => r < n ? n : r > s ? s : r, w = (r, n) => typeof r == "number" && Number.isFinite(r) ? r : n, F = (r, n, s) => n.key === r && s.current.includes(r), I = (r, n, s, u) => s.key === r && n.includes(u.current), de = Q((r, n) => {
  const {
    id: s,
    min: u,
    max: y,
    value: A,
    step: S = se,
    disabled: T = !1,
    noDefault: d = !1,
    onChange: V,
    onKeyDown: R = ee,
    bsSize: m = "md",
    unit: f,
    inputAddon: K,
    errorMessage: D,
    warningMessage: E,
    messageWhiteSpace: v = "normal",
    controls: g,
    placeholder: c,
    digitPrecision: B = ne,
    className: W = "",
    ...j
  } = r, o = Y(""), a = w(u, te), i = w(y, oe), N = C(A, a, i, c, d), [p, k] = Z({
    value: N,
    enteredValue: N,
    isValid: !0
  });
  re(() => {
    k({
      value: C(A, a, i, c, d),
      enteredValue: N,
      isValid: !0
    });
  }, [A, a, i, c, d, N]);
  const L = (e) => {
    if (e === "-" || e === "") {
      k({
        value: e,
        enteredValue: e,
        isValid: !0
      });
      return;
    }
    const t = Number(e), h = !Number.isNaN(t) && t >= a && t <= i, _ = M(t, a, i);
    k({
      value: _,
      enteredValue: t,
      isValid: h
    }), h && V && V(_);
  }, G = (e) => {
    L(e.target.value);
  }, O = (e) => {
    e.ctrlKey || e.altKey || e.metaKey || ((F(".", e, o) || F(",", e, o) || F("-", e, o) || I(",", [".", "-"], e, o) || I(".", [",", "-"], e, o) || I("-", [".", ","], e, o) || e.key === "Process" || e.key === "Dead") && e.preventDefault(), ae.includes(e.key) || e.preventDefault(), o.current = e.key, R(e));
  }, X = () => {
    const e = p.enteredValue;
    if (e === "") {
      V?.();
      return;
    }
    if (!p.value && (d || c))
      return;
    const t = w(Number(e), P), h = M(Number(t.toFixed(B)), a, i);
    L(h);
  }, $ = (e) => {
    const t = e.target;
    t instanceof HTMLInputElement && t.blur();
  }, U = D || E, z = x(
    "input-group",
    m === "sm" && "input-group-sm",
    m === "lg" && "input-group-lg"
  ), H = x(
    "form-control",
    "no-controls",
    m === "sm" && "input-sm",
    m === "lg" && "input-lg",
    (f || g) && !U && "padding-right-5",
    W
  ), q = /* @__PURE__ */ l(
    "input",
    {
      ...j,
      id: s,
      type: "number",
      step: S,
      min: a,
      max: i,
      value: p.isValid ? p.value : p.enteredValue,
      className: H,
      disabled: T,
      onBlur: X,
      onChange: G,
      onKeyDown: O,
      ref: n,
      "aria-label": "number-input",
      placeholder: c,
      onWheel: $
    }
  );
  return /* @__PURE__ */ b("div", { className: z, children: [
    K && /* @__PURE__ */ l("div", { className: "input-group-addon", children: /* @__PURE__ */ l("span", { className: K }) }),
    /* @__PURE__ */ b("div", { className: "form-control-feedback-wrapper", children: [
      q,
      U && /* @__PURE__ */ b(J, { children: [
        D && /* @__PURE__ */ l("span", { className: "form-control-feedback rioglyph rioglyph-error-sign" }),
        E && /* @__PURE__ */ l("span", { className: "form-control-feedback rioglyph rioglyph-warning-sign" }),
        /* @__PURE__ */ l("span", { className: `help-block white-space-${v}`, children: /* @__PURE__ */ l("span", { children: D || E }) })
      ] })
    ] }),
    (f || g) && /* @__PURE__ */ b("div", { className: `input-group-addon ${T ? "disabled pointer-events-none" : ""}`, children: [
      f && f,
      g && g
    ] })
  ] });
});
export {
  oe as DEFAULT_MAX,
  te as DEFAULT_MIN,
  se as DEFAULT_STEP,
  P as DEFAULT_VALUE,
  w as convertNonIntegerToDefault,
  de as default
};
//# sourceMappingURL=NumberInput.js.map
