import{a as e,o as t,s as n,t as r}from"./base-input.Bg_42oFt.js";import{$r as i,Dt as a,Gr as o,Qa as s,Wr as c,cr as l,io as u,kt as d,qr as f,ti as p}from"./index.dkY5s53S.js";var m=u(s());o(),i();function h(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function g(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?h(Object(n),!0).forEach(function(t){_(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):h(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var v=p(`div`,function(e){return g(g({},n(g(g({$positive:!1},e),{},{$hasIconTrailing:!1}))),{},{width:e.$resize?`fit-content`:`100%`})});v.displayName=`StyledTextAreaRoot`,v.displayName=`StyledTextAreaRoot`;var y=p(`div`,function(t){return e(g({$positive:!1},t))});y.displayName=`StyledTextareaContainer`,y.displayName=`StyledTextareaContainer`;var b=p(`textarea`,function(e){return g(g({},t(e)),{},{resize:e.$resize||`none`})});b.displayName=`StyledTextarea`,b.displayName=`StyledTextarea`;function x(e){"@babel/helpers - typeof";return x=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},x(e)}function S(){return S=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},S.apply(this,arguments)}function C(e,t){return O(e)||D(e,t)||T(e,t)||w()}function w(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function T(e,t){if(e){if(typeof e==`string`)return E(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return E(e,t)}}function E(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function D(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function O(e){if(Array.isArray(e))return e}function k(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function A(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function j(e,t,n){return t&&A(e.prototype,t),n&&A(e,n),Object.defineProperty(e,`prototype`,{writable:!1}),e}function M(e,t){if(typeof t!=`function`&&t!==null)throw 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&&N(e,t)}function N(e,t){return N=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},N(e,t)}function P(e){var t=L();return function(){var n=R(e),r;if(t){var i=R(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return F(this,r)}}function F(e,t){if(t&&(x(t)===`object`||typeof t==`function`))return t;if(t!==void 0)throw TypeError(`Derived constructors may only return object or undefined`);return I(e)}function I(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function L(){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 R(e){return R=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},R(e)}function z(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var B=function(e){M(n,e);var t=P(n);function n(){var e;k(this,n);var r=[...arguments];return e=t.call.apply(t,[this].concat(r)),z(I(e),`state`,{isFocused:e.props.autoFocus||!1}),z(I(e),`onFocus`,function(t){e.setState({isFocused:!0}),e.props.onFocus(t)}),z(I(e),`onBlur`,function(t){e.setState({isFocused:!1}),e.props.onBlur(t)}),e}return j(n,[{key:`render`,value:function(){var e=this.props.overrides,t=e===void 0?{}:e,n=C(c(t.Root,v),2),i=n[0],o=n[1],s=f({Input:{component:b},InputContainer:{component:y}},t);return m.createElement(i,S({"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},o),m.createElement(r,S({},this.props,{type:a.textarea,overrides:s,onFocus:this.onFocus,onBlur:this.onBlur,resize:this.props.resize})))}}]),n}(m.Component);z(B,`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:d.default});var V=6.5,H=1,U=e=>{let t=0,{current:n}=e;return n&&(n.style.height=`auto`,t=n.scrollHeight,n.style.height=``),t},W=(e,t,n)=>e>0&&n.current?Math.abs(e-t)>H:!1,G=(e,t)=>{if(e.current&&t.current){let{offsetHeight:n}=e.current;t.current.minHeight=n,t.current.maxHeight=n*V}},K=(e,t,n)=>e?`${t+H}px`:n?String(n):``,q=e=>e?`${e}px`:``,J=({textareaRef:e,dependencies:t=[]})=>{let n=l(),r=(0,m.useRef)({minHeight:0,maxHeight:0}),[i,a]=(0,m.useState)(0),[o,s]=(0,m.useState)(!1),c=(0,m.useCallback)(()=>{a(U(e))},[e,a]),u=(0,m.useCallback)(()=>{a(0)},[a]);(0,m.useLayoutEffect)(()=>{e.current&&G(e,r)},[e]),(0,m.useLayoutEffect)(()=>{let{minHeight:t}=r.current;s(W(i,t,e))},[i,e]),(0,m.useLayoutEffect)(()=>{c()},[e,c,...t]);let{maxHeight:d}=r.current,f=n.sizes.minElementHeight;return{isExtended:o,height:K(o,i,f),maxHeight:q(d),updateScrollHeight:c,clearScrollHeight:u}};export{B as n,J as t};