import { defineComponent as H, useAttrs as A, useSlots as I, useCssModule as P, ref as y, computed as g, watch as V, onMounted as W, nextTick as $, onBeforeUnmount as j, openBlock as q, createBlock as L, mergeProps as w, unref as h, createSlots as Y, withCtx as _, createElementVNode as F, renderSlot as N } from "vue";
import { getOwnerDomContext as B } from "./utils/helpers.js";
import { _ as U } from "./Field.vue_vue_type_script_setup_true_lang-CJUQxQdh.js";
import { _ as G } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const J = ["id", "aria-errormessage", "aria-invalid", "maxlength", "value", "placeholder", "disabled", "readonly", "rows"], K = /* @__PURE__ */ H({
  name: "ll-textarea",
  __name: "Textarea",
  props: {
    modelValue: { default: "" },
    value: { default: null },
    resize: { type: [Boolean, Object], default: !1 },
    placeholder: { default: void 0 },
    rows: { default: void 0 },
    maxlength: { default: void 0 },
    addBottomSpace: { type: Boolean },
    errorText: {},
    hintText: {},
    id: {},
    errorId: {},
    isReadOnly: { type: Boolean },
    isRequired: { type: Boolean },
    label: {},
    showOptionalInLabel: { type: Boolean },
    isLabelSrOnly: { type: Boolean },
    fieldset: { type: Boolean },
    isDisabled: { type: Boolean },
    disabled: { type: Boolean }
  },
  emits: ["update:model-value"],
  setup(z, { emit: R }) {
    const c = A(), O = I(), v = P(), t = z, T = R, f = y(), d = y(), C = g(() => t.isReadOnly || "readonly" in c && c.readonly !== !1), S = g(() => {
      const e = { ...c };
      return delete e["data-test"], delete e.class, e;
    });
    V(
      () => t.resize,
      (e) => {
        var a;
        e ? x() : (a = d.value) == null || a.disconnect();
      }
    );
    const M = (e) => {
      T("update:model-value", e.target.value);
    }, x = () => {
      d.value || !f.value || (d.value = new ResizeObserver((e) => {
        const a = e[0];
        if (!a)
          return;
        const r = a.target, { ownerDoc: o, ownerWin: n } = B(r), s = b(r) || o.documentElement, { scrollTop: u } = s;
        let l = 0;
        if (s === o.documentElement) {
          const { top: i, height: p } = k(r), { innerHeight: m } = n;
          l = Math.max(i + p - (m + u), 0);
        } else {
          const { top: i, height: p } = r.getBoundingClientRect(), { top: m } = s.getBoundingClientRect(), { offsetHeight: D } = s, E = i - m;
          l = Math.max(E + p - D, 0);
        }
        l && requestAnimationFrame(() => {
          s.scrollTop = u + l;
        });
      }), d.value.observe(f.value));
    }, b = (e) => {
      const { ownerDoc: a, ownerWin: r } = B(e), o = e.parentElement;
      if (!o)
        return null;
      const { overflowY: n } = r.getComputedStyle(o);
      return n !== "visible" ? o : o === a.body ? a.documentElement : b(o);
    }, k = (e) => {
      const { offsetWidth: a, offsetHeight: r } = e;
      let o = 0, n = 0;
      const s = function({ offsetLeft: u, offsetTop: l, offsetParent: i }) {
        o += u, n += l, i && s(i);
      };
      return s(e), {
        top: n,
        left: o,
        width: a,
        height: r
      };
    };
    return W(async () => {
      var e;
      if (t.value !== null)
        throw new Error("ll-input: use :model-value or v-model instead of :value.");
      if (c.onInput)
        throw new Error("ll-input: use the @update:model-value event instead of @input");
      (typeof t.resize == "boolean" && t.resize || (e = t.resize) != null && e.forceBrowserScroll) && (await $(), x());
    }), j(() => {
      var e;
      (e = d.value) == null || e.disconnect();
    }), (e, a) => (q(), L(U, w(t, {
      class: ["stash-textarea", [h(v).root]],
      "data-test": "stash-textarea"
    }), Y({
      default: _(({ fieldId: r, fieldErrorId: o, hasError: n }) => [
        F("textarea", w({
          id: r,
          ref_key: "textareaRef",
          ref: f,
          "aria-errormessage": o,
          "aria-invalid": n,
          class: [
            h(v).textarea,
            "border border-ice-500",
            {
              "stash-textarea--error border-red-500 text-red-500": n,
              "text-ice-700 hover:border-ice-500 focus:border-blue-500 active:border-blue-500": !n && !t.disabled,
              "resize-y": t.resize,
              "min-h-[100px]": !t.rows,
              "resize-none": !t.resize
            }
          ],
          maxlength: t.maxlength,
          value: t.modelValue,
          "data-test": "stash-textarea|textarea",
          placeholder: t.placeholder
        }, S.value, {
          disabled: t.disabled,
          readonly: C.value,
          rows: t.rows,
          onInput: M
        }), null, 16, J)
      ]),
      _: 2
    }, [
      h(O).hint ? {
        name: "hint",
        fn: _(() => [
          N(e.$slots, "hint")
        ]),
        key: "0"
      } : void 0
    ]), 1040, ["class"]));
  }
}), Q = "_root_enoYj", X = "_textarea_MbhBm", Z = {
  root: Q,
  textarea: X
}, ee = {
  $style: Z
}, ne = /* @__PURE__ */ G(K, [["__cssModules", ee]]);
export {
  ne as default
};
//# sourceMappingURL=Textarea.js.map
