import e from"../_util/warning.mjs";import t from"../_util/classNames.mjs";import n from"../_util/omit.mjs";import r from"../_util/raf.mjs";import i from"../vc-resize-observer/index.mjs";import a from"../_util/BaseInput.mjs";import{textAreaProps as o}from"./inputProps.mjs";import s from"./calculateNodeHeight.mjs";import{computed as c,createVNode as l,defineComponent as u,getCurrentInstance as d,onBeforeUnmount as f,ref as p,watch as m,watchEffect as h}from"vue";var g=0,_=1,v=2,y=u({compatConfig:{MODE:3},name:`ResizableTextArea`,inheritAttrs:!1,props:o(),setup(o,{attrs:u,emit:y,expose:b}){let x=p(),S=p({}),C=p(v);f(()=>{r.cancel(void 0),r.cancel(void 0)});let w=()=>{try{if(x.value&&document.activeElement===x.value.input){let e=x.value.getSelectionStart(),t=x.value.getSelectionEnd(),n=x.value.getScrollTop();x.value.setSelectionRange(e,t),x.value.setScrollTop(n)}}catch{}},T=p(),E=p();h(()=>{let e=o.autoSize||o.autosize;e?(T.value=e.minRows,E.value=e.maxRows):(T.value=void 0,E.value=void 0)});let D=c(()=>!!(o.autoSize||o.autosize)),O=()=>{C.value=g};m([()=>o.value,T,E,D],()=>{D.value&&O()},{immediate:!0});let k=p();m([C,x],()=>{if(x.value)if(C.value===g)C.value=_;else if(C.value===_){let e=s(x.value.input,!1,T.value,E.value);C.value=v,k.value=e}else w()},{immediate:!0,flush:`post`});let A=d(),j=p(),M=()=>{r.cancel(j.value)},N=e=>{C.value===v&&(y(`resize`,e),D.value&&(M(),j.value=r(()=>{O()})))};f(()=>{M()}),b({resizeTextarea:()=>{O()},textArea:c(()=>x.value?.input),instance:A}),e(o.autosize===void 0,`Input.TextArea`,`autosize is deprecated, please use autoSize instead.`);let P=()=>{let{prefixCls:e,disabled:r}=o,s=n(o,[`prefixCls`,`onPressEnter`,`autoSize`,`autosize`,`defaultValue`,`allowClear`,`type`,`maxlength`,`valueModifiers`]),c=t(e,u.class,{[`${e}-disabled`]:r}),d=D.value?k.value:null,f=[u.style,S.value,d],p={...s,...u,style:f,class:c};return(C.value===g||C.value===_)&&f.push({overflowX:`hidden`,overflowY:`hidden`}),p.autofocus||delete p.autofocus,p.rows===0&&delete p.rows,l(i,{onResize:N,disabled:!D.value},{default:()=>[l(a,{...p,ref:x,tag:`textarea`},null)]})};return()=>P()}});export{y as default};