import { jsxs as S, jsx as o } from "react/jsx-runtime";
import { useFocusRing as j } from "@react-aria/focus";
import { useRef as v, useEffect as D } from "react";
import H from "react-textarea-autosize";
import M from "../../foundation/Icon/Generated/IconExclamationMarkTriangle.es.js";
import { useMemoizedId as V } from "../../hooks/useMemoizedId.es.js";
import { FOCUS_STYLE as W } from "../../utilities/focusStyle.es.js";
import { merge as x } from "../../utilities/merge.es.js";
import { validationClassMap as A, Validation as r } from "../../utilities/validation.es.js";
import { LoadingCircle as B, LoadingCircleSize as K } from "../LoadingCircle/LoadingCircle.es.js";
const R = ({
  id: d,
  value: g,
  required: b = !1,
  decorator: a,
  placeholder: h,
  disabled: s = !1,
  onInput: n,
  onBlur: c,
  validation: e = r.Default,
  minRows: w,
  maxRows: k,
  autosize: m = !1,
  resizeable: T = !0,
  onFocus: u,
  selectable: z = !1,
  focusOnMount: f,
  onEnterPressed: i,
  ...C
}) => {
  const L = m ? H : "textarea", l = v(null);
  D(() => {
    if (f) {
      const t = setTimeout(() => {
        var p;
        (p = l.current) == null || p.focus();
      }, 0);
      return () => clearTimeout(t);
    }
  }, [f]);
  const N = (t) => {
    t.key === "Enter" && (i == null || i(t));
  }, y = (t) => {
    c && c(t.target.value);
  }, E = (t) => {
    n && n(t.target.value);
  }, { isFocusVisible: I, focusProps: F } = j({ isTextInput: !0, within: !0 });
  return /* @__PURE__ */ S("div", { className: "tw-relative", ...F, children: [
    a ? /* @__PURE__ */ o(
      "div",
      {
        className: "tw-absolute tw-top-2 tw-left-2 tw-inline-flex tw-items-end tw-text-black-80",
        "data-test-id": "decorator",
        children: a
      }
    ) : null,
    /* @__PURE__ */ o(
      L,
      {
        ...m ? { maxRows: k, minRows: w } : { rows: w },
        onClick: () => {
          var t;
          return (t = l.current) == null ? void 0 : t.focus();
        },
        id: V(d),
        ref: l,
        value: g,
        placeholder: h,
        required: b,
        className: x([
          "tw-w-full tw-p-2 tw-border tw-rounded tw-text-s tw-outline-none tw-transition tw-placeholder-black-60",
          !!a && "tw-pl-7 ",
          s ? "tw-border-black-5 tw-bg-black-5 tw-text-black-40" : "tw-text-black tw-border-black-20 hover:tw-border-line-x-strong focus-within:tw-border-line-xx-strong focus-within:hover:tw-border-line-xx-strong",
          I && W,
          A[e],
          !T && "tw-resize-none",
          e === r.Error && "tw-pr-8"
        ]),
        disabled: s,
        onBlur: y,
        onFocus: (t) => {
          z && t.target.select(), u && u(t);
        },
        onInput: E,
        onKeyDown: N,
        "data-test-id": "textarea",
        ...C
      }
    ),
    e === r.Loading && /* @__PURE__ */ o("span", { className: "tw-absolute tw-top-[-0.55rem] tw-right-[-0.55rem] tw-bg-white tw-rounded-full tw-p-[2px] tw-border tw-border-black-10", children: /* @__PURE__ */ o(B, { size: K.ExtraSmall }) }),
    (e === r.Error || e === r.Warning) && /* @__PURE__ */ o(
      "span",
      {
        className: x([
          "tw-absolute tw-top-[0.6rem] tw-right-[0.6rem]",
          e === r.Error && "tw-text-text-negative",
          e === r.Warning && "tw-text-text-warning"
        ]),
        "data-test-id": "error-state-exclamation-mark-icon",
        children: /* @__PURE__ */ o(M, {})
      }
    )
  ] });
};
R.displayName = "FondueLegacyTextarea";
export {
  R as LegacyTextarea
};
//# sourceMappingURL=LegacyTextarea.es.js.map
