import{o as he,d as N,_ as _e,a as I,k as Se,m as se,b as Le}from"./@babel-BJZJ6yB5.js";import{c as k}from"./classnames-3ZYesfuy.js";import{u as Be,B as Oe,r as me}from"./rc-input-D7u8Xn6W.js";import{n as xe,k as ge,w as pe}from"./rc-util-uI9ZRjCe.js";import{a as u,R as h}from"./react-CXoDaX02.js";import{R as De}from"./rc-resize-observer-C0Qk4-AA.js";var He=`
  min-height:0 !important;
  max-height:none !important;
  height:0 !important;
  visibility:hidden !important;
  overflow:hidden !important;
  position:absolute !important;
  z-index:-1000 !important;
  top:0 !important;
  right:0 !important;
  pointer-events: none !important;
`,Ke=["letter-spacing","line-height","padding-top","padding-bottom","font-family","font-weight","font-size","font-variant","text-rendering","text-transform","width","text-indent","padding-left","padding-right","border-width","box-sizing","word-break","white-space"],re={},v;function ke(e){var C=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,a=e.getAttribute("id")||e.getAttribute("data-reactid")||e.getAttribute("name");if(C&&re[a])return re[a];var r=window.getComputedStyle(e),S=r.getPropertyValue("box-sizing")||r.getPropertyValue("-moz-box-sizing")||r.getPropertyValue("-webkit-box-sizing"),d=parseFloat(r.getPropertyValue("padding-bottom"))+parseFloat(r.getPropertyValue("padding-top")),o=parseFloat(r.getPropertyValue("border-bottom-width"))+parseFloat(r.getPropertyValue("border-top-width")),i=Ke.map(function(l){return"".concat(l,":").concat(r.getPropertyValue(l))}).join(";"),x={sizingStyle:i,paddingSize:d,borderSize:o,boxSizing:S};return C&&a&&(re[a]=x),x}function Ye(e){var C=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:null;v||(v=document.createElement("textarea"),v.setAttribute("tab-index","-1"),v.setAttribute("aria-hidden","true"),v.setAttribute("name","hiddenTextarea"),document.body.appendChild(v)),e.getAttribute("wrap")?v.setAttribute("wrap",e.getAttribute("wrap")):v.removeAttribute("wrap");var S=ke(e,C),d=S.paddingSize,o=S.borderSize,i=S.boxSizing,x=S.sizingStyle;v.setAttribute("style","".concat(x,";").concat(He)),v.value=e.value||e.placeholder||"";var l=void 0,s=void 0,R,m=v.scrollHeight;if(i==="border-box"?m+=o:i==="content-box"&&(m-=d),a!==null||r!==null){v.value=" ";var T=v.scrollHeight-d;a!==null&&(l=T*a,i==="border-box"&&(l=l+d+o),m=Math.max(l,m)),r!==null&&(s=T*r,i==="border-box"&&(s=s+d+o),R=m>s?"":"hidden",m=Math.min(s,m))}var c={height:m,overflowY:R,resize:"none"};return l&&(c.minHeight=l),s&&(c.maxHeight=s),c}var je=["prefixCls","defaultValue","value","autoSize","onResize","className","style","disabled","onChange","onInternalAutoSize"],oe=0,ie=1,le=2,We=u.forwardRef(function(e,C){var a=e,r=a.prefixCls,S=a.defaultValue,d=a.value,o=a.autoSize,i=a.onResize,x=a.className,l=a.style,s=a.disabled,R=a.onChange;a.onInternalAutoSize;var m=he(a,je),T=xe(S,{value:d,postState:function(g){return g??""}}),c=N(T,2),_=c[0],X=c[1],U=function(g){X(g.target.value),R?.(g)},w=u.useRef();u.useImperativeHandle(C,function(){return{textArea:w.current}});var $=u.useMemo(function(){return o&&_e(o)==="object"?[o.minRows,o.maxRows]:[]},[o]),Y=N($,2),f=Y[0],z=Y[1],V=!!o,q=u.useState(le),L=N(q,2),y=L[0],F=L[1],B=u.useState(),j=N(B,2),J=j[0],W=j[1],P=function(){F(oe)};ge(function(){V&&P()},[d,f,z,V]),ge(function(){if(y===oe)F(ie);else if(y===ie){var b=Ye(w.current,!1,f,z);F(le),W(b)}},[y]);var O=u.useRef(),M=function(){pe.cancel(O.current)},Q=function(g){y===le&&(i?.(g),o&&(M(),O.current=pe(function(){P()})))};u.useEffect(function(){return M},[]);var Z=V?J:null,D=I(I({},l),Z);return(y===oe||y===ie)&&(D.overflowY="hidden",D.overflowX="hidden"),u.createElement(De,{onResize:Q,disabled:!(o||i)},u.createElement("textarea",Se({},m,{ref:w,style:D,className:k(r,x,se({},"".concat(r,"-disabled"),s)),disabled:s,value:_,onChange:U})))}),Ze=["defaultValue","value","onFocus","onBlur","onChange","allowClear","maxLength","onCompositionStart","onCompositionEnd","suffix","prefixCls","showCount","count","className","style","disabled","hidden","classNames","styles","onResize","onClear","onPressEnter","readOnly","autoSize","onKeyDown"],et=h.forwardRef(function(e,C){var a,r=e.defaultValue,S=e.value,d=e.onFocus,o=e.onBlur,i=e.onChange,x=e.allowClear,l=e.maxLength,s=e.onCompositionStart,R=e.onCompositionEnd,m=e.suffix,T=e.prefixCls,c=T===void 0?"rc-textarea":T,_=e.showCount,X=e.count,U=e.className,w=e.style,$=e.disabled,Y=e.hidden,f=e.classNames,z=e.styles,V=e.onResize,q=e.onClear,L=e.onPressEnter,y=e.readOnly,F=e.autoSize,B=e.onKeyDown,j=he(e,Ze),J=xe(r,{value:S,defaultValue:r}),W=N(J,2),P=W[0],O=W[1],M=P==null?"":String(P),Q=h.useState(!1),Z=N(Q,2),D=Z[0],b=Z[1],g=h.useRef(!1),Re=h.useState(null),ue=N(Re,2),be=ue[0],ze=ue[1],de=u.useRef(null),ee=u.useRef(null),E=function(){var t;return(t=ee.current)===null||t===void 0?void 0:t.textArea},ce=function(){E().focus()};u.useImperativeHandle(C,function(){var n;return{resizableTextArea:ee.current,focus:ce,blur:function(){E().blur()},nativeElement:((n=de.current)===null||n===void 0?void 0:n.nativeElement)||E()}}),u.useEffect(function(){b(function(n){return!$&&n})},[$]);var ye=h.useState(null),fe=N(ye,2),te=fe[0],Ce=fe[1];h.useEffect(function(){if(te){var n;(n=E()).setSelectionRange.apply(n,Le(te))}},[te]);var p=Be(X,_),H=(a=p.max)!==null&&a!==void 0?a:l,we=Number(H)>0,ae=p.strategy(M),Ee=!!H&&ae>H,ve=function(t,A){var G=A;!g.current&&p.exceedFormatter&&p.max&&p.strategy(A)>p.max&&(G=p.exceedFormatter(A,{max:p.max}),A!==G&&Ce([E().selectionStart||0,E().selectionEnd||0])),O(G),me(t.currentTarget,t,i,G)},Ae=function(t){g.current=!0,s?.(t)},Ie=function(t){g.current=!1,ve(t,t.currentTarget.value),R?.(t)},Ne=function(t){ve(t,t.target.value)},Te=function(t){t.key==="Enter"&&L&&L(t),B?.(t)},Ve=function(t){b(!0),d?.(t)},$e=function(t){b(!1),o?.(t)},Fe=function(t){O(""),ce(),me(E(),t,i)},ne=m,K;p.show&&(p.showFormatter?K=p.showFormatter({value:M,count:ae,maxLength:H}):K="".concat(ae).concat(we?" / ".concat(H):""),ne=h.createElement(h.Fragment,null,ne,h.createElement("span",{className:k("".concat(c,"-data-count"),f?.count),style:z?.count},K)));var Pe=function(t){var A;V?.(t),(A=E())!==null&&A!==void 0&&A.style.height&&ze(!0)},Me=!F&&!_&&!x;return h.createElement(Oe,{ref:de,value:M,allowClear:x,handleReset:Fe,suffix:ne,prefixCls:c,classNames:I(I({},f),{},{affixWrapper:k(f?.affixWrapper,se(se({},"".concat(c,"-show-count"),_),"".concat(c,"-textarea-allow-clear"),x))}),disabled:$,focused:D,className:k(U,Ee&&"".concat(c,"-out-of-range")),style:I(I({},w),be&&!Me?{height:"auto"}:{}),dataAttrs:{affixWrapper:{"data-count":typeof K=="string"?K:void 0}},hidden:Y,readOnly:y,onClear:q},h.createElement(We,Se({},j,{autoSize:F,maxLength:l,onKeyDown:Te,onChange:Ne,onFocus:Ve,onBlur:$e,onCompositionStart:Ae,onCompositionEnd:Ie,className:k(f?.textarea),style:I(I({},z?.textarea),{},{resize:w?.resize}),disabled:$,prefixCls:c,onResize:Pe,ref:ee,readOnly:y})))});export{et as T};
