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