import{aI as ae,az as re,aJ as ie,aK as le,aL as oe,E as se,G as T,a0 as x,ab as ce,J as ue,I as de,d as fe,S as ge,U as N,at as me,aM as he,W as C,a2 as be,ak as ve,aE as ye,aN as Ce,a3 as Ie,X as I,V as xe,j as o,M as k,aO as Se,N as w,aq as O,a8 as Me,A as Ve,aP as ke,O as we}from"./ResizeObserver.es.b7226882.js";import{c as Ee,C as Te}from"./index.40f703b6.js";import{u as Pe}from"./use-id.5d5e6e63.js";function Fe(e){return Array.isArray(e)?!e.length:e===0?!1:!e}function Le(e,r){return!(r.required&&Fe(e)||r.pattern&&!r.pattern.test(String(e)))}function Ae(e,r){return new Promise(i=>{const s=r.validator(e,r);if(le(s)){s.then(i);return}i(s)})}function R(e,r){const{message:i}=r;return oe(i)?i(e,r):i||""}function Be({target:e}){e.composing=!0}function _({target:e}){e.composing&&(e.composing=!1,e.dispatchEvent(new Event("input")))}function Ne(e,r){const i=ae();e.style.height="auto";let s=e.scrollHeight;if(ie(r)){const{maxHeight:l,minHeight:g}=r;l!==void 0&&(s=Math.min(s,l)),g!==void 0&&(s=Math.max(s,g))}s&&(e.style.height=`${s}px`,re(i))}function Oe(e){return e==="number"?{type:"text",inputmode:"decimal"}:e==="digit"?{type:"tel",inputmode:"numeric"}:{type:e}}function E(e){return[...e].length}function Re(e,r){return[...e].slice(0,r).join("")}const[_e,u]=se("field"),ze={id:String,name:String,leftIcon:String,rightIcon:String,autofocus:Boolean,clearable:Boolean,maxlength:T,formatter:Function,clearIcon:x("clear"),modelValue:ce(""),inputAlign:String,placeholder:String,autocomplete:String,errorMessage:String,clearTrigger:x("focus"),formatTrigger:x("onChange"),error:{type:Boolean,default:null},disabled:{type:Boolean,default:null},readonly:{type:Boolean,default:null}},We=ue({},Ee,ze,{rows:T,type:x("text"),rules:Array,autosize:[Boolean,Object],labelWidth:T,labelClass:de,labelAlign:String,showWordLimit:Boolean,errorMessageAlign:String,colon:{type:Boolean,default:null}});var De=fe({name:_e,props:We,emits:["blur","focus","clear","keypress","click-input","click-left-icon","click-right-icon","update:modelValue"],setup(e,{emit:r,slots:i}){const s=Pe(),l=ge({focused:!1,validateFailed:!1,validateMessage:""}),g=N(),S=N(),{parent:d}=me(he),m=()=>{var t;return String((t=e.modelValue)!=null?t:"")},f=t=>{if(k(e[t]))return e[t];if(d&&k(d.props[t]))return d.props[t]},z=C(()=>{const t=f("readonly");if(e.clearable&&!t){const n=m()!=="",a=e.clearTrigger==="always"||e.clearTrigger==="focus"&&l.focused;return n&&a}return!1}),P=C(()=>S.value&&i.input?S.value():e.modelValue),W=t=>t.reduce((n,a)=>n.then(()=>{if(l.validateFailed)return;let{value:c}=P;if(a.formatter&&(c=a.formatter(c,a)),!Le(c,a)){l.validateFailed=!0,l.validateMessage=R(c,a);return}if(a.validator)return Ae(c,a).then(y=>{y&&typeof y=="string"?(l.validateFailed=!0,l.validateMessage=y):y===!1&&(l.validateFailed=!0,l.validateMessage=R(c,a))})}),Promise.resolve()),h=()=>{l.validateFailed&&(l.validateFailed=!1,l.validateMessage="")},F=(t=e.rules)=>new Promise(n=>{h(),t?W(t).then(()=>{l.validateFailed?n({name:e.name,message:l.validateMessage}):n()}):n()}),M=t=>{if(d&&e.rules){const n=d.props.validateTrigger===t,a=e.rules.filter(c=>c.trigger?c.trigger===t:n);a.length&&F(a)}},D=t=>{const{maxlength:n}=e;if(k(n)&&E(t)>n){const a=m();return a&&E(a)===+n?a:Re(t,+n)}return t},b=(t,n="onChange")=>{if(t=D(t),e.type==="number"||e.type==="digit"){const a=e.type==="number";t=Se(t,a,a)}e.formatter&&n===e.formatTrigger&&(t=e.formatter(t)),g.value&&g.value.value!==t&&(g.value.value=t),t!==e.modelValue&&r("update:modelValue",t)},j=t=>{t.target.composing||b(t.target.value)},V=()=>{var t;return(t=g.value)==null?void 0:t.blur()},$=()=>{var t;return(t=g.value)==null?void 0:t.focus()},v=()=>{const t=g.value;e.type==="textarea"&&e.autosize&&t&&Ne(t,e.autosize)},q=t=>{l.focused=!0,r("focus",t),I(v),f("readonly")&&V()},K=t=>{f("readonly")||(l.focused=!1,b(m(),"onBlur"),r("blur",t),M("onBlur"),I(v),ke())},L=t=>r("click-input",t),H=t=>r("click-left-icon",t),J=t=>r("click-right-icon",t),U=t=>{O(t),r("update:modelValue",""),r("clear",t)},A=C(()=>{if(typeof e.error=="boolean")return e.error;if(d&&d.props.showError&&l.validateFailed)return!0}),Y=C(()=>{const t=f("labelWidth");if(t)return{width:be(t)}}),G=t=>{t.keyCode===13&&(!(d&&d.props.submitOnEnter)&&e.type!=="textarea"&&O(t),e.type==="search"&&V()),r("keypress",t)},B=()=>e.id||`${s}-input`,X=()=>{const t=u("control",[f("inputAlign"),{error:A.value,custom:!!i.input,"min-height":e.type==="textarea"&&!e.autosize}]);if(i.input)return o("div",{class:t,onClick:L},[i.input()]);const n={id:B(),ref:g,name:e.name,rows:e.rows!==void 0?+e.rows:void 0,class:t,value:e.modelValue,disabled:f("disabled"),readonly:f("readonly"),autofocus:e.autofocus,placeholder:e.placeholder,autocomplete:e.autocomplete,"aria-labelledby":e.label?`${s}-label`:void 0,onBlur:K,onFocus:q,onInput:j,onClick:L,onChange:_,onKeypress:G,onCompositionend:_,onCompositionstart:Be};return e.type==="textarea"?o("textarea",n,null):o("input",Me(Oe(e.type),n),null)},Q=()=>{const t=i["left-icon"];if(e.leftIcon||t)return o("div",{class:u("left-icon"),onClick:H},[t?t():o(w,{name:e.leftIcon,classPrefix:e.iconPrefix},null)])},Z=()=>{const t=i["right-icon"];if(e.rightIcon||t)return o("div",{class:u("right-icon"),onClick:J},[t?t():o(w,{name:e.rightIcon,classPrefix:e.iconPrefix},null)])},p=()=>{if(e.showWordLimit&&e.maxlength){const t=E(m());return o("div",{class:u("word-limit")},[o("span",{class:u("word-num")},[t]),Ve("/"),e.maxlength])}},ee=()=>{if(d&&d.props.showErrorMessage===!1)return;const t=e.errorMessage||l.validateMessage;if(t){const n=i["error-message"],a=f("errorMessageAlign");return o("div",{class:u("error-message",a)},[n?n({message:t}):t])}},te=()=>{const t=f("colon")?":":"";if(i.label)return[i.label(),t];if(e.label)return o("label",{id:`${s}-label`,for:B()},[e.label+t])},ne=()=>[o("div",{class:u("body")},[X(),z.value&&o(w,{name:e.clearIcon,class:u("clear"),onTouchstart:U},null),Z(),i.button&&o("div",{class:u("button")},[i.button()])]),p(),ee()];return ve({blur:V,focus:$,validate:F,formValue:P,resetValidation:h}),ye(Ce,{customValue:S,resetValidation:h,validateWithTrigger:M}),Ie(()=>e.modelValue,()=>{b(m()),h(),M("onChange"),I(v)}),xe(()=>{b(m(),e.formatTrigger),I(v)}),()=>{const t=f("disabled"),n=f("labelAlign"),a=te(),c=Q();return o(Te,{size:e.size,icon:e.leftIcon,class:u({error:A.value,disabled:t,[`label-${n}`]:n}),center:e.center,border:e.border,isLink:e.isLink,clickable:e.clickable,titleStyle:Y.value,valueClass:u("value"),titleClass:[u("label",[n,{required:e.required}]),e.labelClass],arrowDirection:e.arrowDirection},{icon:c?()=>c:null,title:a?()=>a:null,value:ne,extra:i.extra})}}});const Ke=we(De);export{Ke as F,ze as f};