import { jsx as i, jsxs as u } from "react/jsx-runtime";
import { useRef as T, forwardRef as k, useId as B, isValidElement as H } from "react";
import { c as L } from "./button-DBX_tvfJ.mjs";
import { F as M } from "./field-error-text-CBSX8dGx.mjs";
import { F as S } from "./field-helper-text-C5ee4SFV.mjs";
import { r as D } from "./check-circle-filled.es-umBwOv5_.mjs";
import { r as G } from "./close.es-BPmk2wkU.mjs";
import { L as J } from "./label-7sJe5-pX.mjs";
import { a as K } from "./spinner-DRQN6YdK.mjs";
import { c as Q } from "./bind-CU-R61T-.mjs";
const U = {
  "purpur-text-field": "_purpur-text-field_1n0q1_1",
  "purpur-text-field__label": "_purpur-text-field__label_1n0q1_7",
  "purpur-text-field__label-text": "_purpur-text-field__label-text_1n0q1_12",
  "purpur-text-field__field-row": "_purpur-text-field__field-row_1n0q1_15",
  "purpur-text-field__frame": "_purpur-text-field__frame_1n0q1_19",
  "purpur-text-field__frame--negative": "_purpur-text-field__frame--negative_1n0q1_26",
  "purpur-text-field__input-container": "_purpur-text-field__input-container_1n0q1_29",
  "purpur-text-field__input-container--disabled": "_purpur-text-field__input-container--disabled_1n0q1_40",
  "purpur-text-field__input-container--readonly": "_purpur-text-field__input-container--readonly_1n0q1_43",
  "purpur-text-field__input-container--has-clear-button": "_purpur-text-field__input-container--has-clear-button_1n0q1_46",
  "purpur-text-field__input-container--end-adornment": "_purpur-text-field__input-container--end-adornment_1n0q1_49",
  "purpur-text-field__input": "_purpur-text-field__input_1n0q1_29",
  "purpur-text-field__input-container--start-adornment": "_purpur-text-field__input-container--start-adornment_1n0q1_55",
  "purpur-text-field__input-container--negative": "_purpur-text-field__input-container--negative_1n0q1_61",
  "purpur-text-field__input--valid": "_purpur-text-field__input--valid_1n0q1_109",
  "purpur-text-field__input--error": "_purpur-text-field__input--error_1n0q1_109",
  "purpur-text-field__input--negative": "_purpur-text-field__input--negative_1n0q1_130",
  "purpur-text-field__adornment-container": "_purpur-text-field__adornment-container_1n0q1_146",
  "purpur-text-field__valid-icon": "_purpur-text-field__valid-icon_1n0q1_151",
  "purpur-text-field__valid-icon--negative": "_purpur-text-field__valid-icon--negative_1n0q1_154"
}, W = (d) => T(d), _ = Q.bind(U), e = "purpur-text-field", C = k(
  ({
    ["data-testid"]: d,
    className: I,
    clearButtonAriaLabel: x,
    beforeField: b,
    afterField: v,
    endAdornment: s,
    errorText: l,
    helperText: h,
    hideRequiredAsterisk: R = !1,
    label: $,
    loading: q = !1,
    onClear: y,
    startAdornment: w,
    valid: O = !1,
    negative: n = !1,
    ...t
  }, p) => {
    const V = B(), o = t.id ?? V, r = (a) => d ? `${d}-${a}` : void 0, N = O && !l, c = h ? `${o}-helper-text` : void 0, f = [w].filter((a) => !!a), g = (typeof t.value == "number" ? t.value !== void 0 : t.value?.length) && !t.disabled && !t.readOnly && !q && y && x, F = W(null), j = (a) => {
      F.current = a, typeof p == "function" ? p(a) : p && (p.current = a);
    }, E = () => {
      y?.(), F.current?.focus();
    }, m = [
      q && /* @__PURE__ */ i(
        K,
        {
          disabled: t.disabled,
          size: "xs",
          "data-testid": r("spinner"),
          negative: n
        },
        "spinner"
      ),
      g && /* @__PURE__ */ i(
        L,
        {
          negative: n,
          variant: "tertiary-purple",
          onClick: E,
          iconOnly: !0,
          "aria-label": x ?? "",
          "data-testid": r("clear-button"),
          tabIndex: -1,
          children: /* @__PURE__ */ i(G, { size: "xs" })
        },
        "clear-button"
      ),
      N && /* @__PURE__ */ i(
        D,
        {
          "data-testid": r("valid-icon"),
          className: _(`${e}__valid-icon`, {
            [`${e}__valid-icon--negative`]: n
          })
        },
        "valid-icon"
      )
    ].filter((a) => !!a), z = _(`${e}__input-container`, {
      [`${e}__input-container--start-adornment`]: f.length,
      [`${e}__input-container--end-adornment`]: m.length || s,
      [`${e}__input-container--disabled`]: t.disabled,
      [`${e}__input-container--has-clear-button`]: g,
      [`${e}__input-container--readonly`]: t.readOnly && !t.disabled,
      [`${e}__input-container--negative`]: n
    });
    return /* @__PURE__ */ u("div", { className: _(I, e), children: [
      $ && /* @__PURE__ */ u(
        J,
        {
          htmlFor: o,
          className: _(`${e}__label`),
          "data-testid": r("label"),
          disabled: t.disabled,
          negative: n,
          children: [
            t.required && !R && /* @__PURE__ */ i("span", { "aria-hidden": !0, children: "*" }),
            $
          ]
        }
      ),
      /* @__PURE__ */ u("div", { className: _(`${e}__field-row`), children: [
        !!b && b,
        /* @__PURE__ */ u("div", { className: z, children: [
          !!f.length && /* @__PURE__ */ i(
            "div",
            {
              "data-testid": r("start-adornments"),
              className: _(`${e}__adornment-container`),
              children: f
            }
          ),
          /* @__PURE__ */ i(
            "input",
            {
              ...t,
              id: o,
              ref: j,
              "data-testid": r("input"),
              "aria-describedby": t["aria-describedby"] || c,
              "aria-invalid": t["aria-invalid"] || !!l,
              className: _([
                `${e}__input`,
                {
                  [`${e}__input--valid`]: N,
                  [`${e}__input--error`]: !!l,
                  [`${e}__input--negative`]: n
                }
              ])
            }
          ),
          /* @__PURE__ */ i(
            "div",
            {
              className: _(`${e}__frame`, {
                [`${e}__frame--negative`]: n
              })
            }
          ),
          (!!m.length || s) && /* @__PURE__ */ u(
            "div",
            {
              "data-testid": r("end-adornments"),
              className: _(`${e}__adornment-container`),
              children: [
                m,
                s
              ]
            }
          )
        ] }),
        !!v && v
      ] }),
      c && /* @__PURE__ */ i(
        S,
        {
          "data-testid": r("helper-text"),
          id: c,
          negative: n,
          disabled: t.disabled,
          children: h
        }
      ),
      l && /* @__PURE__ */ i(M, { "data-testid": r("error-text"), negative: n, children: l })
    ] });
  }
);
C.displayName = "TextField";
const _e = (d) => H(d) && d.type.displayName === C.displayName;
export {
  C as T,
  _e as i
};
//# sourceMappingURL=text-field-PKAaXO1N.mjs.map
