import e from"../_util/classNames.mjs";import t from"../_util/omit.mjs";import{useInjectDisabled as n}from"../config-provider/DisabledContext.mjs";import r from"../config-provider/hooks/useConfigInject.mjs";import{getMergedStatus as i,getStatusClassNames as a}from"../_util/statusUtils.mjs";import{FormItemInputContext as o,useInjectFormItemContext as s}from"../form/FormItemContext.mjs";import c from"./style/index.mjs";import{fixControlledValue as ee,resolveOnChange as l,triggerFocus as u}from"../vc-input/utils/commonUtils.mjs";import{textAreaProps as d}from"./inputProps.mjs";import f from"./ClearableLabeledInput.mjs";import p from"./ResizableTextArea.mjs";import{computed as m,createVNode as h,defineComponent as g,getCurrentInstance as _,nextTick as v,shallowRef as y,watch as b,watchEffect as x}from"vue";function S(e,t){return[...e||``].slice(0,t).join(``)}function C(e,t,n,r){let i=n;return e?i=S(n,r):[...t||``].length<n.length&&[...n||``].length>r&&(i=t),i}var w=g({compatConfig:{MODE:3},name:`ATextarea`,inheritAttrs:!1,props:d(),setup(d,{attrs:g,expose:w,emit:T}){let E=s(),D=o.useInject(),O=m(()=>i(D.status,d.status)),k=y(d.value??d.defaultValue),A=y(),j=y(``),{prefixCls:M,size:N,direction:P}=r(`input`,d),[F,I]=c(M),L=n(),R=m(()=>d.showCount===``||d.showCount||!1),z=m(()=>Number(d.maxlength)>0),B=y(!1),V=y(),H=y(0),U=e=>{B.value=!0,V.value=j.value,H.value=e.currentTarget.selectionStart,T(`compositionstart`,e)},W=e=>{B.value=!1;let t=e.currentTarget.value;z.value&&(t=C(H.value>=d.maxlength+1||H.value===V.value?.length,V.value,t,d.maxlength)),t!==j.value&&(J(t),l(e.currentTarget,e,Z,t)),T(`compositionend`,e)},G=_();b(()=>d.value,()=>{`value`in G.vnode.props,k.value=d.value??``});let K=e=>{u(A.value?.textArea,e)},q=()=>{A.value?.textArea?.blur()},J=(e,t)=>{k.value!==e&&(d.value===void 0?k.value=e:v(()=>{A.value.textArea.value!==j.value&&A.value?.instance.update?.()}),v(()=>{t&&t()}))},Y=e=>{e.keyCode===13&&T(`pressEnter`,e),T(`keydown`,e)},X=e=>{let{onBlur:t}=d;t?.(e),E.onFieldBlur()},Z=e=>{T(`update:value`,e.target.value),T(`change`,e),T(`input`,e),E.onFieldChange()},Q=e=>{l(A.value.textArea,e,Z),J(``,()=>{K()})},$=e=>{let t=e.target.value;if(k.value!==t){if(z.value){let n=e.target;t=C(n.selectionStart>=d.maxlength+1||n.selectionStart===t.length||!n.selectionStart,j.value,t,d.maxlength)}l(e.currentTarget,e,Z,t),J(t)}},te=()=>{let{class:e}=g,{bordered:n=!0}=d,r={...t(d,[`allowClear`]),...g,class:[{[`${M.value}-borderless`]:!n,[`${e}`]:e&&!R.value,[`${M.value}-sm`]:N.value===`small`,[`${M.value}-lg`]:N.value===`large`},a(M.value,O.value),I.value],disabled:L.value,showCount:null,prefixCls:M.value,onInput:$,onChange:$,onBlur:X,onKeydown:Y,onCompositionstart:U,onCompositionend:W};return d.valueModifiers?.lazy&&delete r.onInput,h(p,{...r,id:r?.id??E.id.value,ref:A,maxlength:d.maxlength,lazy:d.lazy},null)};return w({focus:K,blur:q,resizableTextArea:A}),x(()=>{let e=ee(k.value);!B.value&&z.value&&(d.value===null||d.value===void 0)&&(e=S(e,d.maxlength)),j.value=e}),()=>{let{maxlength:t,bordered:n=!0,hidden:r}=d,{style:i,class:a}=g,o=h(f,{...d,...g,prefixCls:M.value,inputType:`text`,handleReset:Q,direction:P.value,bordered:n,style:R.value?void 0:i,hashId:I.value,disabled:d.disabled??L.value,value:j.value,status:d.status},{element:te});if(R.value||D.hasFeedback){let n=[...j.value].length,s=``;s=typeof R.value==`object`?R.value.formatter({value:j.value,count:n,maxlength:t}):`${n}${z.value?` / ${t}`:``}`,o=h(`div`,{hidden:r,class:e(`${M.value}-textarea`,{[`${M.value}-textarea-rtl`]:P.value===`rtl`,[`${M.value}-textarea-show-count`]:R.value,[`${M.value}-textarea-in-form-item`]:D.isFormItemInput},`${M.value}-textarea-show-count`,a,I.value),style:i,"data-count":typeof s==`object`?void 0:s},[o,D.hasFeedback&&h(`span`,{class:`${M.value}-textarea-suffix`},[D.feedbackIcon])])}return F(o)}}});export{w as default};