import { jsx as r, jsxs as x } from "react/jsx-runtime";
import { forwardRef as K, useState as I } from "react";
import { isNil as O } from "es-toolkit/predicate";
import { noop as N } from "es-toolkit/function";
import c from "../../utils/classNames.js";
import Q from "../clearableInput/ClearableInput.js";
const v = (l, i, u) => {
  const t = l.length;
  return t >= i && t <= u;
}, tt = K((l, i) => {
  const {
    defaultValue: u,
    value: t,
    minLength: h = 0,
    maxLength: V,
    clearable: S = !1,
    showValidationState: w,
    validateInitialEmpty: L = !1,
    validationState: m = "warning",
    className: b = "",
    onChange: B = N,
    onBlur: T = N,
    ...y
  } = l, n = V ?? h ?? 0, s = h ?? 0, M = t || u || "", [j, k] = I(M), [$, p] = I(!1), g = !O(t), o = g ? t || "" : j, d = v(o, s, n), a = w ?? (L || o.length > 0 || $), E = m === "error" ? "has-error" : "has-warning", P = m === "error" ? "text-color-danger" : "text-color-warning", f = a && d, C = s > 0 ? s : n, R = `${Math.min(o.length, C)}/${C}`, q = (e, H) => {
    const J = v(e, s, n);
    p(!0), g || k(e), B(e, J, H);
  }, z = (e) => {
    p(!0), T(e);
  }, A = c(
    "form-group",
    "CountedInput",
    a && "has-feedback",
    a && (d ? "has-success" : E),
    b
  ), D = c(
    "input-group-addon",
    "CountedInputCounter text-bold",
    a && (d ? "text-color-success" : P)
  ), F = c("CountedInputCounterValue text-italic", f && "is-hidden"), G = c(
    "CountedInputSuccessIcon rioglyph rioglyph-ok text-color-success",
    f && "is-visible"
  );
  return /* @__PURE__ */ r("div", { className: A, children: /* @__PURE__ */ x("div", { className: "input-group", children: [
    /* @__PURE__ */ r(
      Q,
      {
        ...y,
        ref: i,
        value: o,
        maxLength: n,
        showClearButton: S,
        onChange: q,
        onBlur: z
      }
    ),
    /* @__PURE__ */ x("span", { className: D, children: [
      /* @__PURE__ */ r("span", { className: F, children: R }),
      /* @__PURE__ */ r("span", { className: G, "aria-hidden": !0 })
    ] })
  ] }) });
});
export {
  tt as default
};
//# sourceMappingURL=CountedInput.js.map
