import { j as t } from "../../../_virtual/jsx-runtime.js";
import { forwardRef as D, useState as E, useEffect as C } from "react";
import G from "../../../icons/AlertCircle.js";
import { getId as J } from "../../../utils/index.js";
import { Wrapper as K, LabelWrapper as N, Label as Q, Text as L, Border as U, SupportingText as V, ErrorMessage as X, AssistMessage as Y } from "../styles.js";
import { getCharacterCount as Z } from "../utils.js";
import { Prefix as _, TextFieldInput as v, Sufix as b } from "./styles.js";
function tt({
  autoComplete: F = !1,
  id: x,
  name: s,
  label: e,
  value: n,
  type: S = "text",
  placeholder: w,
  hasError: i = !1,
  errorText: g,
  assistText: d,
  optionalText: y = "Optional",
  disabled: r = !1,
  variant: I = "medium",
  required: T = !0,
  maxChar: j,
  minChar: A,
  showCharCount: u = !1,
  width: M,
  prefix: h,
  suffix: c,
  onSuffixClick: f,
  onChange: P,
  touched: l,
  onBlur: R,
  onFocus: W,
  onPaste: $,
  onKeyUp: k,
  ...p
}, H) {
  const [O, B] = E(0), [a, q] = E(!1);
  C(() => {
    n && typeof n == "string" && B(n.length);
  }, []), C(() => {
    q(typeof l > "u" ? i : i && l);
  }, [i, l]);
  function z(m) {
    B(m.target.value.length), P(m);
  }
  const o = J(p["data-testid"]);
  return /* @__PURE__ */ t.jsxs(K, { "data-testid": o("text-field"), width: M, children: [
    /* @__PURE__ */ t.jsxs(N, { disabled: r, hasLabel: !!(e != null && e.length), children: [
      e && /* @__PURE__ */ t.jsx(Q, { htmlFor: x || `input-${s}`, disabled: r, children: e }),
      !T && !u && /* @__PURE__ */ t.jsx(L, { children: y }),
      u && /* @__PURE__ */ t.jsx(L, { "data-testid": o("char-count"), children: Z(O, j) })
    ] }),
    /* @__PURE__ */ t.jsxs(
      U,
      {
        hasError: a,
        disabled: r,
        hasPrefix: !!h,
        hasSuffix: !!c,
        children: [
          !!h && /* @__PURE__ */ t.jsx(_, { "data-testid": o("prefix"), children: h }),
          /* @__PURE__ */ t.jsx(
            v,
            {
              hasError: a,
              ref: H,
              id: x || `input-${s}`,
              type: S,
              variant: I,
              disabled: r,
              placeholder: w,
              autoComplete: F ? "on" : "off",
              maxLength: j,
              minLength: A,
              value: String(n),
              onChange: z,
              onKeyUp: k,
              onBlur: R,
              onFocus: W,
              onPaste: $,
              "data-trackid": p["data-trackid"],
              "data-testid": o(),
              "aria-label": p["aria-label"] || e,
              name: s
            }
          ),
          !!c && /* @__PURE__ */ t.jsx(
            b,
            {
              "data-testid": o("suffix"),
              hasHandler: !!f,
              onClick: f && f,
              children: c
            }
          )
        ]
      }
    ),
    /* @__PURE__ */ t.jsxs(V, { children: [
      !!g && a && !r && /* @__PURE__ */ t.jsxs(X, { children: [
        /* @__PURE__ */ t.jsx(G, { width: 20, height: 20 }),
        g
      ] }),
      !a && (typeof d == "string" ? /* @__PURE__ */ t.jsx(Y, { children: d }) : d)
    ] })
  ] });
}
const dt = D(tt);
export {
  dt as TextField
};
