import Q from "../../@babel/runtime/helpers/esm/extends.mjs";
import ee from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import w from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import te from "../../@babel/runtime/helpers/esm/typeof.mjs";
import l from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import re from "../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import ae from "../../classnames/index.mjs";
import oe from "../../rc-resize-observer/es/index.mjs";
import M from "../../rc-util/es/hooks/useLayoutEffect.mjs";
import ne from "../../rc-util/es/hooks/useMergedState.mjs";
import N from "../../rc-util/es/raf.mjs";
import * as r from "react";
import ie from "./calculateNodeHeight.mjs";
var se = ["prefixCls", "onPressEnter", "defaultValue", "value", "autoSize", "onResize", "className", "style", "disabled", "onChange", "onInternalAutoSize"], S = 0, v = 1, R = 2, ge = /* @__PURE__ */ r.forwardRef(function(T, V) {
  var e = T, p = e.prefixCls;
  e.onPressEnter;
  var P = e.defaultValue, z = e.value, a = e.autoSize, s = e.onResize, $ = e.className, j = e.style, E = e.disabled, u = e.onChange, f = e.onInternalAutoSize, Z = re(e, se), F = ne(P, {
    value: z,
    postState: function(t) {
      return t ?? "";
    }
  }), _ = l(F, 2), L = _[0], O = _[1], B = function(t) {
    O(t.target.value), u == null || u(t);
  }, o = r.useRef();
  r.useImperativeHandle(V, function() {
    return {
      textArea: o.current
    };
  });
  var D = r.useMemo(function() {
    return a && te(a) === "object" ? [a.minRows, a.maxRows] : [];
  }, [a]), g = l(D, 2), A = g[0], x = g[1], c = !!a, G = function() {
    try {
      if (document.activeElement === o.current) {
        var t = o.current, q = t.selectionStart, J = t.selectionEnd, K = t.scrollTop;
        o.current.setSelectionRange(q, J), o.current.scrollTop = K;
      }
    } catch {
    }
  }, H = r.useState(R), y = l(H, 2), i = y[0], m = y[1], U = r.useState(), I = l(U, 2), W = I[0], X = I[1], b = function() {
    m(S), process.env.NODE_ENV === "test" && (f == null || f());
  };
  M(function() {
    c && b();
  }, [z, A, x, c]), M(function() {
    if (i === S)
      m(v);
    else if (i === v) {
      var n = ie(o.current, !1, A, x);
      m(R), X(n);
    } else
      G();
  }, [i]);
  var h = r.useRef(), C = function() {
    N.cancel(h.current);
  }, Y = function(t) {
    i === R && (s == null || s(t), a && (C(), h.current = N(function() {
      b();
    })));
  };
  r.useEffect(function() {
    return C;
  }, []);
  var k = c ? W : null, d = w(w({}, j), k);
  return (i === S || i === v) && (d.overflowY = "hidden", d.overflowX = "hidden"), /* @__PURE__ */ r.createElement(oe, {
    onResize: Y,
    disabled: !(a || s)
  }, /* @__PURE__ */ r.createElement("textarea", Q({}, Z, {
    ref: o,
    style: d,
    className: ae(p, $, ee({}, "".concat(p, "-disabled"), E)),
    disabled: E,
    value: L,
    onChange: B
  })));
});
export {
  ge as default
};
