import E, { forwardRef as k, useRef as H, useLayoutEffect as B, createElement as G } from "react";
import { dk as Z, dl as J, dm as K, dn as Q, X as ee, _ as te, dp as re, dq as ie, dr as T } from "./index-BJZQSU1O.mjs";
var A = {
  "min-height": "0",
  "max-height": "none",
  height: "0",
  visibility: "hidden",
  overflow: "hidden",
  position: "absolute",
  "z-index": "-1000",
  top: "0",
  right: "0"
}, F = function(t) {
  Object.keys(A).forEach(function(r) {
    t.style.setProperty(r, A[r], "important");
  });
}, a = null, ne = function(t, r) {
  var e = t.scrollHeight;
  return r.sizingStyle.boxSizing === "border-box" ? e + r.borderSize : e - r.paddingSize;
};
function ae(i, t, r, e) {
  r === void 0 && (r = 1), e === void 0 && (e = 1 / 0), a || (a = document.createElement("textarea"), a.setAttribute("tabindex", "-1"), a.setAttribute("aria-hidden", "true"), F(a)), a.parentNode === null && document.body.appendChild(a);
  var n = i.paddingSize, o = i.borderSize, d = i.sizingStyle, c = d.boxSizing;
  Object.keys(d).forEach(function(f) {
    var v = f;
    a.style[v] = d[v];
  }), F(a), a.value = t;
  var l = ne(a, i);
  a.value = "x";
  var h = a.scrollHeight - n, s = h * r;
  c === "border-box" && (s = s + n + o), l = Math.max(s, l);
  var p = h * e;
  return c === "border-box" && (p = p + n + o), l = Math.min(p, l), [l, h];
}
var I = function() {
}, oe = function(t, r) {
  return t.reduce(function(e, n) {
    return e[n] = r[n], e;
  }, {});
}, se = [
  "borderBottomWidth",
  "borderLeftWidth",
  "borderRightWidth",
  "borderTopWidth",
  "boxSizing",
  "fontFamily",
  "fontSize",
  "fontStyle",
  "fontWeight",
  "letterSpacing",
  "lineHeight",
  "paddingBottom",
  "paddingLeft",
  "paddingRight",
  "paddingTop",
  // non-standard
  "tabSize",
  "textIndent",
  // non-standard
  "textRendering",
  "textTransform",
  "width",
  "wordBreak"
], de = !!document.documentElement.currentStyle, le = function(t) {
  var r = window.getComputedStyle(t);
  if (r === null)
    return null;
  var e = oe(se, r), n = e.boxSizing;
  if (n === "")
    return null;
  de && n === "border-box" && (e.width = parseFloat(e.width) + parseFloat(e.borderRightWidth) + parseFloat(e.borderLeftWidth) + parseFloat(e.paddingRight) + parseFloat(e.paddingLeft) + "px");
  var o = parseFloat(e.paddingBottom) + parseFloat(e.paddingTop), d = parseFloat(e.borderBottomWidth) + parseFloat(e.borderTopWidth);
  return {
    sizingStyle: e,
    paddingSize: o,
    borderSize: d
  };
}, pe = function(t) {
  var r = Q(t);
  B(function() {
    var e = function(o) {
      r.current(o);
    };
    return window.addEventListener("resize", e), function() {
      window.removeEventListener("resize", e);
    };
  }, []);
}, ue = function(t, r) {
  var e = t.cacheMeasurements, n = t.maxRows, o = t.minRows, d = t.onChange, c = d === void 0 ? I : d, l = t.onHeightChange, h = l === void 0 ? I : l, s = Z(t, ["cacheMeasurements", "maxRows", "minRows", "onChange", "onHeightChange"]);
  if (process.env.NODE_ENV !== "production" && s.style) {
    if ("maxHeight" in s.style)
      throw new Error("Using `style.maxHeight` for <TextareaAutosize/> is not supported. Please use `maxRows`.");
    if ("minHeight" in s.style)
      throw new Error("Using `style.minHeight` for <TextareaAutosize/> is not supported. Please use `minRows`.");
  }
  var p = s.value !== void 0, f = H(null), v = J(f, r), g = H(0), m = H(), x = function() {
    var u = f.current, S = e && m.current ? m.current : le(u);
    if (S) {
      m.current = S;
      var z = ae(S, u.value || u.placeholder || "x", o, n), y = z[0], R = z[1];
      g.current !== y && (g.current = y, u.style.setProperty("height", y + "px", "important"), h(y, {
        rowHeight: R
      }));
    }
  }, w = function(u) {
    p || x(), c(u);
  };
  return B(x), pe(x), /* @__PURE__ */ G("textarea", K({}, s, {
    onChange: w,
    ref: v
  }));
}, ce = /* @__PURE__ */ k(ue), he = ee((i) => ({
  input: {
    paddingTop: i.spacing.xs,
    paddingBottom: i.spacing.xs
  }
})), ge = Object.defineProperty, fe = Object.defineProperties, ve = Object.getOwnPropertyDescriptors, _ = Object.getOwnPropertySymbols, M = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable, j = (i, t, r) => t in i ? ge(i, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : i[t] = r, b = (i, t) => {
  for (var r in t || (t = {}))
    M.call(t, r) && j(i, r, t[r]);
  if (_)
    for (var r of _(t))
      D.call(t, r) && j(i, r, t[r]);
  return i;
}, C = (i, t) => fe(i, ve(t)), me = (i, t) => {
  var r = {};
  for (var e in i)
    M.call(i, e) && t.indexOf(e) < 0 && (r[e] = i[e]);
  if (i != null && _)
    for (var e of _(i))
      t.indexOf(e) < 0 && D.call(i, e) && (r[e] = i[e]);
  return r;
};
const xe = {
  autosize: !1,
  size: "sm",
  __staticSelector: "Textarea"
}, ye = k((i, t) => {
  const r = te("Textarea", xe, i), {
    autosize: e,
    maxRows: n,
    minRows: o,
    label: d,
    error: c,
    description: l,
    id: h,
    className: s,
    required: p,
    style: f,
    wrapperProps: v,
    classNames: g,
    styles: m,
    size: x,
    __staticSelector: w,
    sx: P,
    errorProps: u,
    descriptionProps: S,
    labelProps: z,
    inputWrapperOrder: y,
    inputContainer: R,
    unstyled: O,
    withAsterisk: q,
    variant: W
  } = r, U = me(r, [
    "autosize",
    "maxRows",
    "minRows",
    "label",
    "error",
    "description",
    "id",
    "className",
    "required",
    "style",
    "wrapperProps",
    "classNames",
    "styles",
    "size",
    "__staticSelector",
    "sx",
    "errorProps",
    "descriptionProps",
    "labelProps",
    "inputWrapperOrder",
    "inputContainer",
    "unstyled",
    "withAsterisk",
    "variant"
  ]), L = re(h), { classes: V, cx: X } = he(), { systemStyles: Y, rest: $ } = ie(U), N = b({
    required: p,
    ref: t,
    error: c,
    id: L,
    classNames: C(b({}, g), { input: X(V.input, g?.input) }),
    styles: m,
    __staticSelector: w,
    size: x,
    multiline: !0,
    unstyled: O,
    variant: W
  }, $);
  return /* @__PURE__ */ E.createElement(T.Wrapper, b(b({
    label: d,
    error: c,
    id: L,
    description: l,
    required: p,
    style: f,
    className: s,
    classNames: g,
    styles: m,
    size: x,
    __staticSelector: w,
    sx: P,
    errorProps: u,
    labelProps: z,
    descriptionProps: S,
    inputContainer: R,
    inputWrapperOrder: y,
    unstyled: O,
    withAsterisk: q,
    variant: W
  }, Y), v), e ? /* @__PURE__ */ E.createElement(T, C(b({}, N), {
    component: ce,
    maxRows: n,
    minRows: o
  })) : /* @__PURE__ */ E.createElement(T, C(b({}, N), {
    component: "textarea",
    rows: o
  })));
});
ye.displayName = "@mantine/core/Textarea";
export {
  ye as T
};
//# sourceMappingURL=Textarea-Gr-nKkZy.mjs.map
