import { jsx as t, jsxs as q } from "react/jsx-runtime";
import { forwardRef as J, useRef as Q, useState as g, useEffect as I } from "react";
import { noop as Y } from "es-toolkit/function";
import Z from "../../utils/classNames.js";
import $, { DEFAULT_MIN as ee, DEFAULT_MAX as ne, DEFAULT_STEP as te, convertNonIntegerToDefault as V, DEFAULT_VALUE as L } from "../numberInput/NumberInput.js";
const oe = 700, re = 50, se = 3, de = J((E, A) => {
  const {
    id: U,
    min: D = ee,
    max: N = ne,
    step: a = te,
    value: o,
    onChange: u,
    onKeyDown: _ = Y,
    disabled: r,
    bsSize: C,
    className: F,
    unit: S,
    inputAddon: H,
    errorMessage: R,
    warningMessage: O,
    messageWhiteSpace: P,
    digitPrecision: m = se,
    placeholder: B,
    noDefault: K,
    ...j
  } = E, n = Q(null), [d, h] = g(!1), [f, T] = g(!1), [s, l] = g(o), b = (e) => {
    n.current !== null && clearTimeout(n.current), n.current = setTimeout(() => {
      e();
    }, oe);
  }, w = (e) => {
    n.current = setTimeout(() => {
      e();
    }, re);
  };
  I(() => {
    s !== o && l(o);
  }, [o]), I(() => {
    s !== o && u && u(s);
  }, [s]), I(() => {
    d && !r && b(y), f && !r && b(M);
  }, [d, f]);
  const v = () => {
    l((e) => {
      const p = V(e, L), i = Number((p + a).toFixed(m));
      return i <= N ? i : e;
    });
  }, x = () => {
    l((e) => {
      const p = V(e, L), i = Number((p - a).toFixed(m));
      return i >= D ? i : e;
    });
  }, y = () => {
    v(), w(y);
  }, M = () => {
    x(), w(M);
  }, k = () => {
    r || (h(!0), v());
  }, z = () => {
    r || (T(!0), x());
  }, c = () => {
    n.current !== null && clearTimeout(n.current), h(!1), T(!1);
  }, G = (e) => {
    e !== void 0 && !(f && d) && l(Number(e)), u?.(e);
  }, W = Z("NumberControl", F);
  return /* @__PURE__ */ t("div", { ...j, className: W, children: /* @__PURE__ */ t(
    $,
    {
      id: U,
      ref: A,
      min: D,
      max: N,
      value: s,
      step: a,
      bsSize: C,
      disabled: r,
      inputAddon: H,
      errorMessage: R,
      warningMessage: O,
      messageWhiteSpace: P,
      controls: /* @__PURE__ */ q("div", { className: "display-flex padding-left-10", onMouseOut: c, onBlur: c, children: [
        /* @__PURE__ */ t(
          "div",
          {
            onMouseDown: z,
            onMouseUp: c,
            role: "button",
            "aria-label": "decrement-button",
            className: "decrementButton display-flex align-items-center text-color-gray hover-text-color-dark cursor-pointer",
            children: /* @__PURE__ */ t("div", { className: "rioglyph rioglyph-minus scale-90" })
          }
        ),
        /* @__PURE__ */ t(
          "div",
          {
            onMouseDown: k,
            onMouseUp: c,
            role: "button",
            "aria-label": "increment-button",
            className: "incrementButton display-flex align-items-center text-color-gray hover-text-color-dark cursor-pointer margin-left-5",
            children: /* @__PURE__ */ t("div", { className: "rioglyph rioglyph-plus scale-90" })
          }
        )
      ] }),
      unit: S,
      onChange: G,
      onKeyDown: _,
      digitPrecision: m,
      placeholder: B,
      noDefault: K
    }
  ) });
});
export {
  de as default
};
//# sourceMappingURL=NumberControl.js.map
