import * as m from "react";
import { useRef as F, useState as P, useCallback as T, useLayoutEffect as b } from "react";
import { aa as O, o as N, ag as R, p as z, ah as B, u as C } from "./index-CsBCemCF.js";
import { a as D, b as K, c as M, B as U } from "./base-input-ChvJQUff.js";
function x(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 c(e) {
  for (var t = 1; t < arguments.length; t++) {
    var r = arguments[t] != null ? arguments[t] : {};
    t % 2 ? x(Object(r), !0).forEach(function(n) {
      L(e, n, r[n]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : x(Object(r)).forEach(function(n) {
      Object.defineProperty(e, n, Object.getOwnPropertyDescriptor(r, n));
    });
  }
  return e;
}
function L(e, t, r) {
  return t in e ? Object.defineProperty(e, t, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = r, e;
}
var _ = O("div", function(e) {
  return c(c({}, D(c(c({
    $positive: !1
  }, e), {}, {
    $hasIconTrailing: !1
  }))), {}, {
    width: e.$resize ? "fit-content" : "100%"
  });
});
_.displayName = "StyledTextAreaRoot";
_.displayName = "StyledTextAreaRoot";
var S = O("div", function(e) {
  return K(c({
    $positive: !1
  }, e));
});
S.displayName = "StyledTextareaContainer";
S.displayName = "StyledTextareaContainer";
var w = O("textarea", function(e) {
  return c(c({}, M(e)), {}, {
    resize: e.$resize || "none"
  });
});
w.displayName = "StyledTextarea";
w.displayName = "StyledTextarea";
function g(e) {
  "@babel/helpers - typeof";
  return g = 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;
  }, g(e);
}
function p() {
  return p = 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;
  }, p.apply(this, arguments);
}
function q(e, t) {
  return X(e) || W(e, t) || G(e, t) || V();
}
function V() {
  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 G(e, t) {
  if (e) {
    if (typeof e == "string") return I(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 I(e, t);
  }
}
function I(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 W(e, t) {
  var r = e == null ? null : typeof Symbol < "u" && e[Symbol.iterator] || e["@@iterator"];
  if (r != null) {
    var n = [], o = !0, i = !1, a, u;
    try {
      for (r = r.call(e); !(o = (a = r.next()).done) && (n.push(a.value), !(t && n.length === t)); o = !0)
        ;
    } catch (s) {
      i = !0, u = s;
    } finally {
      try {
        !o && r.return != null && r.return();
      } finally {
        if (i) throw u;
      }
    }
    return n;
  }
}
function X(e) {
  if (Array.isArray(e)) return e;
}
function Y(e, t) {
  if (!(e instanceof t))
    throw new TypeError("Cannot call a class as a function");
}
function Z(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 J(e, t, r) {
  return t && Z(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 && v(e, t);
}
function v(e, t) {
  return v = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(n, o) {
    return n.__proto__ = o, n;
  }, v(e, t);
}
function k(e) {
  var t = te();
  return function() {
    var n = y(e), o;
    if (t) {
      var i = y(this).constructor;
      o = Reflect.construct(n, arguments, i);
    } else
      o = n.apply(this, arguments);
    return ee(this, o);
  };
}
function ee(e, t) {
  if (t && (g(t) === "object" || typeof t == "function"))
    return t;
  if (t !== void 0)
    throw new TypeError("Derived constructors may only return object or undefined");
  return l(e);
}
function l(e) {
  if (e === void 0)
    throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  return e;
}
function te() {
  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 y(e) {
  return y = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(r) {
    return r.__proto__ || Object.getPrototypeOf(r);
  }, y(e);
}
function f(e, t, r) {
  return t in e ? Object.defineProperty(e, t, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = r, e;
}
var re = /* @__PURE__ */ (function(e) {
  Q(r, e);
  var t = k(r);
  function r() {
    var n;
    Y(this, r);
    for (var o = arguments.length, i = new Array(o), a = 0; a < o; a++)
      i[a] = arguments[a];
    return n = t.call.apply(t, [this].concat(i)), f(l(n), "state", {
      isFocused: n.props.autoFocus || !1
    }), f(l(n), "onFocus", function(u) {
      n.setState({
        isFocused: !0
      }), n.props.onFocus(u);
    }), f(l(n), "onBlur", function(u) {
      n.setState({
        isFocused: !1
      }), n.props.onBlur(u);
    }), n;
  }
  return J(r, [{
    key: "render",
    value: function() {
      var o = this.props.overrides, i = o === void 0 ? {} : o, a = N(i.Root, _), u = q(a, 2), s = u[0], d = u[1], h = R({
        Input: {
          component: w
        },
        InputContainer: {
          component: S
        }
      }, i);
      return /* @__PURE__ */ m.createElement(s, p({
        "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
      }, d), /* @__PURE__ */ m.createElement(U, p({}, this.props, {
        type: B.textarea,
        overrides: h,
        onFocus: this.onFocus,
        onBlur: this.onBlur,
        resize: this.props.resize
      })));
    }
  }]), r;
})(m.Component);
f(re, "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: z.default
});
const ne = 6.5, E = 1, oe = (e) => {
  let t = 0;
  const {
    current: r
  } = e;
  return r && (r.style.height = "auto", t = r.scrollHeight, r.style.height = ""), t;
}, ie = (e, t, r) => e > 0 && r.current ? Math.abs(e - t) > E : !1, ae = (e, t) => {
  if (e.current && t.current) {
    const {
      offsetHeight: r
    } = e.current;
    t.current.minHeight = r, t.current.maxHeight = r * ne;
  }
}, ue = (e, t, r) => e ? `${t + E}px` : r ? String(r) : "", se = (e) => e ? `${e}px` : "", pe = ({
  textareaRef: e,
  dependencies: t = []
}) => {
  const r = C(), n = F({
    minHeight: 0,
    maxHeight: 0
  }), [o, i] = P(0), [a, u] = P(!1), s = T(() => {
    i(oe(e));
  }, [e, i]), d = T(() => {
    i(0);
  }, [i]);
  b(() => {
    e.current && ae(e, n);
  }, [e]), b(() => {
    const {
      minHeight: A
    } = n.current;
    u(ie(o, A, e));
  }, [o, e]), b(() => {
    s();
  }, [e, s, ...t]);
  const {
    maxHeight: h
  } = n.current, H = r.sizes.minElementHeight, j = ue(a, o, H), $ = se(h);
  return {
    isExtended: a,
    height: j,
    maxHeight: $,
    updateScrollHeight: s,
    clearScrollHeight: d
  };
};
export {
  re as T,
  pe as u
};
//# sourceMappingURL=useTextInputAutoExpand-DWOWjQ4t.js.map
