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