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