import { jsx as l, jsxs as v, Fragment as b } from "react/jsx-runtime";
import h, { forwardRef as g, createContext as P, useCallback as H, useEffect as I, useRef as R } from "react";
import { createSlotRecipeContext as T, mergeRefs as S } from "@chakra-ui/react";
import { useRecipe as w } from "@chakra-ui/react/styled-system";
import { $ as C, a as E } from "./utils-B6pV5ewr.es.js";
import { $ as F } from "./useHover-BQRSM3qT.es.js";
import { $ as y } from "./useFocusRing-FPt2Rwil.es.js";
import { $ as M } from "./mergeProps-Dsl8k3Ig.es.js";
import { e as N } from "./extract-style-props-BdibuNZ7.es.js";
import { m as V } from "./index-C2qW4ynb.es.js";
import { $ as A } from "./useObjectRef-CaJ5pgjX.es.js";
import { $ as j } from "./useTextField-yuaT8-G4.es.js";
const L = /* @__PURE__ */ P({});
let k = (i) => {
  let { onHoverStart: t, onHoverChange: o, onHoverEnd: r, ...e } = i;
  return e;
};
const D = /* @__PURE__ */ g(function(t, o) {
  [t, o] = C(t, o, L);
  let { hoverProps: r, isHovered: e } = F(t), { isFocused: a, isFocusVisible: d, focusProps: s } = y({
    isTextInput: !0,
    autoFocus: t.autoFocus
  }), n = !!t["aria-invalid"] && t["aria-invalid"] !== "false", c = E({
    ...t,
    values: {
      isHovered: e,
      isFocused: a,
      isFocusVisible: d,
      isDisabled: t.disabled || !1,
      isInvalid: n
    },
    defaultClassName: "react-aria-TextArea"
  });
  return /* @__PURE__ */ h.createElement("textarea", {
    ...M(k(t), s, r),
    ...c,
    ref: o,
    "data-focused": a || void 0,
    "data-disabled": t.disabled || void 0,
    "data-hovered": e || void 0,
    "data-focus-visible": d || void 0,
    "data-invalid": n || void 0
  });
}), { withContext: u, withProvider: _ } = /* @__PURE__ */ T({
  key: "multilineTextInput"
}), G = /* @__PURE__ */ _("div", "root"), q = /* @__PURE__ */ u("div", "leadingElement"), z = /* @__PURE__ */ u("textarea", "textarea");
function B(i, t = {}) {
  const { enabled: o = !1 } = t, r = H(() => {
    const e = i.current;
    if (!e || !o) return;
    e.style.height = "auto";
    const a = e.scrollHeight, d = window.getComputedStyle(e), s = parseInt(d.maxHeight, 10), n = !isNaN(s) && s > 0 ? Math.min(a, s) : a;
    e.style.height = `${n}px`;
  }, [o]);
  I(() => {
    const e = i.current;
    if (!e || !o) return;
    r();
    const a = () => {
      r();
    };
    return e.addEventListener("input", a), () => {
      e.removeEventListener("input", a);
    };
  }, [r, o]);
}
const J = (i) => {
  const {
    ref: t,
    leadingElement: o,
    rows: r = 1,
    autoGrow: e = !1,
    ...a
  } = i, d = w({ recipe: V }), s = R(null), n = A(S(s, t)), [c, f] = d.splitVariantProps(a), [m, p] = N(f), { inputProps: $ } = j(p, n);
  B(n, { enabled: e });
  const x = {
    "data-disabled": a.isDisabled ? "true" : void 0,
    "data-invalid": a.isInvalid ? "true" : "false"
  };
  return /* @__PURE__ */ l(
    G,
    {
      className: i?.className,
      ...c,
      ...m,
      ...x,
      children: /* @__PURE__ */ v(b, { children: [
        o && /* @__PURE__ */ l(q, { children: o }),
        /* @__PURE__ */ l(z, { asChild: !0, children: /* @__PURE__ */ l(D, { ref: n, rows: r, ...$ }) })
      ] })
    }
  );
};
J.displayName = "MultilineTextInput";
export {
  J as M
};
//# sourceMappingURL=multiline-text-input-CrDTYrM3.es.js.map
