import { m as A, r as u, aX as g, aY as F, bi as R, bP as _, bQ as C } from "./index-6wLGsgHc.js";
import { A as z, D as I, V as D, t as B } from "./base-input-DjjpNP8Y-D5Wig0hH.js";
function w(e, t) {
  var r = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(e);
    t && (n = n.filter(function(o) {
      return Object.getOwnPropertyDescriptor(e, o).enumerable;
    })), r.push.apply(r, n);
  }
  return r;
}
function l(e) {
  for (var t = 1; t < arguments.length; t++) {
    var r = arguments[t] != null ? arguments[t] : {};
    t % 2 ? w(Object(r), !0).forEach(function(n) {
      N(e, n, r[n]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : w(Object(r)).forEach(function(n) {
      Object.defineProperty(e, n, Object.getOwnPropertyDescriptor(r, n));
    });
  }
  return e;
}
function N(e, t, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e;
}
var v = g("div", function(e) {
  return l(l({}, z(l(l({
    $positive: !1
  }, e), {}, {
    $hasIconTrailing: !1
  }))), {}, {
    width: e.$resize ? "fit-content" : "100%"
  });
});
v.displayName = "StyledTextAreaRoot";
v.displayName = "StyledTextAreaRoot";
var O = g("div", function(e) {
  return I(l({
    $positive: !1
  }, e));
});
O.displayName = "StyledTextareaContainer";
O.displayName = "StyledTextareaContainer";
var j = g("textarea", function(e) {
  return l(l({}, D(e)), {}, {
    resize: e.$resize || "none"
  });
});
j.displayName = "StyledTextarea";
j.displayName = "StyledTextarea";
function h(e) {
  "@babel/helpers - typeof";
  return h = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(t) {
    return typeof t;
  } : function(t) {
    return t && typeof Symbol == "function" && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
  }, h(e);
}
function y() {
  return y = Object.assign ? Object.assign.bind() : function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var r = arguments[t];
      for (var n in r) Object.prototype.hasOwnProperty.call(r, n) && (e[n] = r[n]);
    }
    return e;
  }, y.apply(this, arguments);
}
function k(e, t) {
  return K(e) || U(e, t) || L(e, t) || q();
}
function q() {
  throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
}
function L(e, t) {
  if (e) {
    if (typeof e == "string") return S(e, t);
    var r = Object.prototype.toString.call(e).slice(8, -1);
    if (r === "Object" && e.constructor && (r = e.constructor.name), r === "Map" || r === "Set") return Array.from(e);
    if (r === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)) return S(e, t);
  }
}
function S(e, t) {
  (t == null || t > e.length) && (t = e.length);
  for (var r = 0, n = new Array(t); r < t; r++) n[r] = e[r];
  return n;
}
function U(e, t) {
  var r = e == null ? null : typeof Symbol < "u" && e[Symbol.iterator] || e["@@iterator"];
  if (r != null) {
    var n = [], o = !0, a = !1, i, s;
    try {
      for (r = r.call(e); !(o = (i = r.next()).done) && (n.push(i.value), !(t && n.length === t)); o = !0) ;
    } catch (c) {
      a = !0, s = c;
    } finally {
      try {
        !o && r.return != null && r.return();
      } finally {
        if (a) throw s;
      }
    }
    return n;
  }
}
function K(e) {
  if (Array.isArray(e)) return e;
}
function M(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
}
function V(e, t) {
  for (var r = 0; r < t.length; r++) {
    var n = t[r];
    n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, n.key, n);
  }
}
function Y(e, t, r) {
  return t && V(e.prototype, t), Object.defineProperty(e, "prototype", {
    writable: !1
  }), e;
}
function Q(e, t) {
  if (typeof t != "function" && t !== null) throw new TypeError("Super expression must either be null or a function");
  e.prototype = Object.create(t && t.prototype, {
    constructor: {
      value: e,
      writable: !0,
      configurable: !0
    }
  }), Object.defineProperty(e, "prototype", {
    writable: !1
  }), t && m(e, t);
}
function m(e, t) {
  return m = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(r, n) {
    return r.__proto__ = n, r;
  }, m(e, t);
}
function X(e) {
  var t = G();
  return function() {
    var r = b(e), n;
    if (t) {
      var o = b(this).constructor;
      n = Reflect.construct(r, arguments, o);
    } else n = r.apply(this, arguments);
    return Z(this, n);
  };
}
function Z(e, t) {
  if (t && (h(t) === "object" || typeof t == "function")) return t;
  if (t !== void 0) throw new TypeError("Derived constructors may only return object or undefined");
  return f(e);
}
function f(e) {
  if (e === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  return e;
}
function G() {
  if (typeof Reflect > "u" || !Reflect.construct || Reflect.construct.sham) return !1;
  if (typeof Proxy == "function") return !0;
  try {
    return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
    })), !0;
  } catch {
    return !1;
  }
}
function b(e) {
  return b = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(t) {
    return t.__proto__ || Object.getPrototypeOf(t);
  }, b(e);
}
function p(e, t, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e;
}
var J = /* @__PURE__ */ (function(e) {
  Q(r, e);
  var t = X(r);
  function r() {
    var n;
    M(this, r);
    for (var o = arguments.length, a = new Array(o), i = 0; i < o; i++) a[i] = arguments[i];
    return n = t.call.apply(t, [this].concat(a)), p(f(n), "state", {
      isFocused: n.props.autoFocus || !1
    }), p(f(n), "onFocus", function(s) {
      n.setState({
        isFocused: !0
      }), n.props.onFocus(s);
    }), p(f(n), "onBlur", function(s) {
      n.setState({
        isFocused: !1
      }), n.props.onBlur(s);
    }), n;
  }
  return Y(r, [{
    key: "render",
    value: function() {
      var n = this.props.overrides, o = n === void 0 ? {} : n, a = F(o.Root, v), i = k(a, 2), s = i[0], c = i[1], d = R({
        Input: {
          component: j
        },
        InputContainer: {
          component: O
        }
      }, o);
      return /* @__PURE__ */ u.createElement(s, y({
        "data-baseweb": "textarea",
        $isFocused: this.state.isFocused,
        $isReadOnly: this.props.readOnly,
        $disabled: this.props.disabled,
        $error: this.props.error,
        $positive: this.props.positive,
        $required: this.props.required,
        $resize: this.props.resize
      }, c), /* @__PURE__ */ u.createElement(B, y({}, this.props, {
        type: C.textarea,
        overrides: d,
        onFocus: this.onFocus,
        onBlur: this.onBlur,
        resize: this.props.resize
      })));
    }
  }]), r;
})(u.Component);
p(J, "defaultProps", {
  autoFocus: !1,
  disabled: !1,
  readOnly: !1,
  error: !1,
  name: "",
  onBlur: function() {
  },
  onChange: function() {
  },
  onKeyDown: function() {
  },
  onKeyPress: function() {
  },
  onKeyUp: function() {
  },
  onFocus: function() {
  },
  overrides: {},
  placeholder: "",
  required: !1,
  rows: 3,
  size: _.default
});
const W = 6.5, P = 1, ee = (e) => {
  let t = 0;
  const {
    current: r
  } = e;
  return r && (r.style.height = "auto", t = r.scrollHeight, r.style.height = ""), t;
}, te = (e, t, r) => e > 0 && r.current ? Math.abs(e - t) > P : !1, re = (e, t) => {
  if (e.current && t.current) {
    const {
      offsetHeight: r
    } = e.current;
    t.current.minHeight = r, t.current.maxHeight = r * W;
  }
}, ne = (e, t, r) => e ? `${t + P}px` : r ? String(r) : "", oe = (e) => e ? `${e}px` : "", ue = ({
  textareaRef: e,
  dependencies: t = []
}) => {
  const r = A(), n = u.useRef({
    minHeight: 0,
    maxHeight: 0
  }), [o, a] = u.useState(0), [i, s] = u.useState(!1), c = u.useCallback(() => {
    a(ee(e));
  }, [e, a]), d = u.useCallback(() => {
    a(0);
  }, [a]);
  u.useLayoutEffect(() => {
    e.current && re(e, n);
  }, [e]), u.useLayoutEffect(() => {
    const {
      minHeight: H
    } = n.current;
    s(te(o, H, e));
  }, [o, e]), u.useLayoutEffect(() => {
    c();
  }, [e, c, ...t]);
  const {
    maxHeight: x
  } = n.current, E = r.sizes.minElementHeight, $ = ne(i, o, E), T = oe(x);
  return {
    isExtended: i,
    height: $,
    maxHeight: T,
    updateScrollHeight: c,
    clearScrollHeight: d
  };
};
export {
  ue as p,
  J as r
};
//# sourceMappingURL=useTextInputAutoExpand-Di5cdshf-AADZhTlW.js.map
