import{defineComponent as U,shallowRef as p,watch as y,computed as W,onMounted as q,createVNode as v,Fragment as G,nextTick as N}from"vue";import H from"../_util/BaseInput.mjs";import z from"../_util/classNames.mjs";import V from"../_util/omit.mjs";import J from"./BaseInput.mjs";import{inputProps as Q}from"./inputProps.mjs";import{fixControlledValue as $,triggerFocus as X,resolveOnChange as B,hasAddon as Y,hasPrefixSuffix as Z}from"./utils/commonUtils.mjs";const ie=U({name:"VCInput",inheritAttrs:!1,props:Q(),setup(n,{slots:l,attrs:h,expose:I,emit:s}){const o=p(n.value===void 0?n.defaultValue:n.value),i=p(!1),u=p(),C=p();y(()=>n.value,()=>{o.value=n.value}),y(()=>n.disabled,()=>{n.disabled&&(i.value=!1)});const m=e=>{u.value&&X(u.value.input,e)},R=()=>{u.value.input?.blur()},P=(e,t,a)=>{u.value.input?.setSelectionRange(e,t,a)},S=()=>{u.value.input?.select()};I({focus:m,blur:R,input:W(()=>u.value.input?.input),stateValue:o,setSelectionRange:P,select:S});const g=e=>{s("change",e)},w=(e,t)=>{o.value!==e&&(n.value===void 0?o.value=e:N(()=>{u.value.input.value!==o.value&&C.value?.$forceUpdate()}),N(()=>{t&&t()}))},b=e=>{const{value:t}=e.target;if(o.value===t)return;const a=e.target.value;B(u.value.input,e,g),w(a)},A=e=>{e.keyCode===13&&s("pressEnter",e),s("keydown",e)},F=e=>{i.value=!0,s("focus",e)},E=e=>{i.value=!1,s("blur",e)},M=e=>{B(u.value.input,e,g),w("",()=>{m()})},k=()=>{const{addonBefore:e=l.addonBefore,addonAfter:t=l.addonAfter,disabled:a,valueModifiers:r={},htmlSize:x,autocomplete:f,prefixCls:c,inputClassName:L,prefix:j=l.prefix?.(),suffix:D=l.suffix?.(),allowClear:O,type:T="text"}=n,d={...V(n,["prefixCls","onPressEnter","addonBefore","addonAfter","prefix","suffix","allowClear","defaultValue","size","bordered","htmlSize","lazy","showCount","valueModifiers","showCount","affixWrapperClassName","groupClassName","inputClassName","wrapperClassName"]),...h,autocomplete:f,onChange:b,onInput:b,onFocus:F,onBlur:E,onKeydown:A,class:z(c,{[`${c}-disabled`]:a},L,!Y({addonAfter:t,addonBefore:e})&&!Z({prefix:j,suffix:D,allowClear:O})&&h.class),ref:u,key:"ant-input",size:x,type:T,lazy:n.lazy};return r.lazy&&delete d.onInput,d.autofocus||delete d.autofocus,v(H,V(d,["size"]),null)},K=()=>{const{maxlength:e,suffix:t=l.suffix?.(),showCount:a,prefixCls:r}=n,x=Number(e)>0;if(t||a){const f=[...$(o.value)].length,c=typeof a=="object"?a.formatter({count:f,maxlength:e}):`${f}${x?` / ${e}`:""}`;return v(G,null,[!!a&&v("span",{class:z(`${r}-show-count-suffix`,{[`${r}-show-count-has-suffix`]:!!t})},[c]),t])}return null};return q(()=>{}),()=>{const{prefixCls:e,disabled:t,...a}=n;return v(J,{...a,...h,ref:C,prefixCls:e,inputElement:k(),handleReset:M,value:$(o.value),focused:i.value,triggerFocus:m,suffix:K(),disabled:t},l)}}});export{ie as default};
