import { jsxs as T, jsx as r } from "react/jsx-runtime";
import { useRef as f, useMemo as y, useEffect as C } from "react";
import { createSlotRecipeContext as S, mergeRefs as O } from "@chakra-ui/react";
import { useSlotRecipe as k } from "@chakra-ui/react/styled-system";
import { c as q } from "./utils-B6pV5ewr.es.js";
import { $ as u, a as j } from "./Input-Cmg08oRP.es.js";
import { e as w } from "./extract-style-props-BdibuNZ7.es.js";
import { t as L } from "./index-C2qW4ynb.es.js";
import { $ as N } from "./useObjectRef-CaJ5pgjX.es.js";
import { $ as D } from "./mergeProps-Dsl8k3Ig.es.js";
import { $ as z } from "./useTextField-yuaT8-G4.es.js";
const { withProvider: F, withContext: n } = /* @__PURE__ */ S({
  key: "textInput"
}), M = /* @__PURE__ */ F("div", "root"), V = /* @__PURE__ */ n(
  "div",
  "leadingElement"
), A = /* @__PURE__ */ n("input", "input"), B = /* @__PURE__ */ n(
  "div",
  "trailingElement"
), m = (a) => {
  const {
    leadingElement: s,
    trailingElement: d,
    ref: x,
    ...$
  } = a, v = k({ recipe: L }), [b, R] = v.splitVariantProps($), i = f(null), t = f(null), c = N(O(t, x)), [I, g] = w(R), e = q(
    u
  ), P = y(
    () => ({
      ...e,
      isDisabled: e?.isDisabled ?? e?.disabled,
      isRequired: e?.isRequired ?? e?.required,
      isReadOnly: e?.isReadOnly ?? e?.readOnly,
      // Explicit boolean coercion for aria-invalid: "false" string is truthy!
      isInvalid: e?.isInvalid ?? (e?.["aria-invalid"] === !0 || e?.["aria-invalid"] === "true" ? !0 : e?.["aria-invalid"] === !1 || e?.["aria-invalid"] === "false" ? !1 : void 0),
      disabled: void 0,
      required: void 0,
      readOnly: void 0
    }),
    [e]
  ), h = D(P, g), { inputProps: o } = z(
    h,
    c
  ), E = {
    "data-disabled": o.disabled ? "true" : void 0,
    "data-invalid": o["aria-invalid"] ? "true" : "false"
  };
  return C(() => {
    const l = (p) => {
      i.current && i.current.contains(p.target) && t.current && p.target !== t.current && t.current.focus();
    };
    return document.addEventListener("click", l), () => {
      document.removeEventListener("click", l);
    };
  }, []), /* @__PURE__ */ T(
    M,
    {
      ref: i,
      className: a?.className,
      ...b,
      ...I,
      ...E,
      children: [
        s && /* @__PURE__ */ r(V, { children: s }),
        /* @__PURE__ */ r(A, { asChild: !0, children: /* @__PURE__ */ r(j, { ref: c, ...o }) }),
        d && /* @__PURE__ */ r(B, { children: d })
      ]
    }
  );
};
m.displayName = "TextInput";
const ee = /* @__PURE__ */ Object.assign(m, {
  Context: u
});
export {
  ee as T
};
//# sourceMappingURL=text-input-CCiZeQad.es.js.map
