import{b1 as me,aY as he,b2 as be,aB as ye,ax as ve,j as Ie,t as B,n as w,ao as xe,A as Se,x as Ce,d as Ve,aG as Ee,O as ke,i as A,ae as we,E as x,G as j,w as Me,y as k,o as Te,ak as Le,g as u,ay as I,aw as q,b3 as Ae,al as H,I as P,ap as Pe,$ as Re,b4 as Be,m as _e,h as Oe,b5 as De,b6 as Ne,D as We}from"./index-1d4a9afa.js";import{c as Fe,C as ze}from"./index-a27d7671.js";function G(t){return Array.isArray(t)?!t.length:t===0?!1:!t}function $e(t,i){if(G(t)){if(i.required)return!1;if(i.validateEmpty===!1)return!0}return!(i.pattern&&!i.pattern.test(String(t)))}function je(t,i){return new Promise(l=>{const d=i.validator(t,i);if(ye(d)){d.then(l);return}l(d)})}function K(t,i){const{message:l}=i;return ve(l)?l(t,i):l||""}function qe({target:t}){t.composing=!0}function Y({target:t}){t.composing&&(t.composing=!1,t.dispatchEvent(new Event("input")))}function He(t,i){const l=me();t.style.height="auto";let d=t.scrollHeight;if(be(i)){const{maxHeight:r,minHeight:c}=i;r!==void 0&&(d=Math.min(d,r)),c!==void 0&&(d=Math.max(d,c))}d&&(t.style.height=`${d}px`,he(l))}function Ke(t){return t==="number"?{type:"text",inputmode:"decimal"}:t==="digit"?{type:"tel",inputmode:"numeric"}:{type:t}}function y(t){return[...t].length}function R(t,i){return[...t].slice(0,i).join("")}const[Ye,m]=Ie("field"),Ge={id:String,name:String,leftIcon:String,rightIcon:String,autofocus:Boolean,clearable:Boolean,maxlength:B,formatter:Function,clearIcon:w("clear"),modelValue:xe(""),inputAlign:String,placeholder:String,autocomplete:String,errorMessage:String,enterkeyhint:String,clearTrigger:w("focus"),formatTrigger:w("onChange"),error:{type:Boolean,default:null},disabled:{type:Boolean,default:null},readonly:{type:Boolean,default:null}},Ue=Se({},Fe,Ge,{rows:B,type:w("text"),rules:Array,autosize:[Boolean,Object],labelWidth:B,labelClass:Ce,labelAlign:String,showWordLimit:Boolean,errorMessageAlign:String,colon:{type:Boolean,default:null}});var Je=Ve({name:Ye,props:Ue,emits:["blur","focus","clear","keypress","clickInput","endValidate","startValidate","clickLeftIcon","clickRightIcon","update:modelValue"],setup(t,{emit:i,slots:l}){const d=Ee(),r=ke({status:"unvalidated",focused:!1,validateMessage:""}),c=A(),_=A(),M=A(),{parent:h}=we(Be),v=()=>{var e;return String((e=t.modelValue)!=null?e:"")},f=e=>{if(I(t[e]))return t[e];if(h&&I(h.props[e]))return h.props[e]},U=x(()=>{const e=f("readonly");if(t.clearable&&!e){const a=v()!=="",n=t.clearTrigger==="always"||t.clearTrigger==="focus"&&r.focused;return a&&n}return!1}),O=x(()=>M.value&&l.input?M.value():t.modelValue),J=e=>e.reduce((a,n)=>a.then(()=>{if(r.status==="failed")return;let{value:o}=O;if(n.formatter&&(o=n.formatter(o,n)),!$e(o,n)){r.status="failed",r.validateMessage=K(o,n);return}if(n.validator)return G(o)&&n.validateEmpty===!1?void 0:je(o,n).then(s=>{s&&typeof s=="string"?(r.status="failed",r.validateMessage=s):s===!1&&(r.status="failed",r.validateMessage=K(o,n))})}),Promise.resolve()),S=()=>{r.status="unvalidated",r.validateMessage=""},D=()=>i("endValidate",{status:r.status,message:r.validateMessage}),N=(e=t.rules)=>new Promise(a=>{S(),e?(i("startValidate"),J(e).then(()=>{r.status==="failed"?(a({name:t.name,message:r.validateMessage}),D()):(r.status="passed",a(),D())})):a()}),T=e=>{if(h&&t.rules){const{validateTrigger:a}=h.props,n=q(a).includes(e),o=t.rules.filter(s=>s.trigger?q(s.trigger).includes(e):n);o.length&&N(o)}},Q=e=>{var a;const{maxlength:n}=t;if(I(n)&&y(e)>+n){const o=v();if(o&&y(o)===+n)return o;const s=(a=c.value)==null?void 0:a.selectionEnd;if(r.focused&&s){const g=[...e],b=g.length-+n;return g.splice(s-b,b),g.join("")}return R(e,+n)}return e},C=(e,a="onChange")=>{const n=e;e=Q(e);const o=y(n)-y(e);if(t.type==="number"||t.type==="digit"){const g=t.type==="number";e=Ae(e,g,g)}let s=0;if(t.formatter&&a===t.formatTrigger){const{formatter:g,maxlength:b}=t;if(e=g(e),I(b)&&y(e)>+b&&(e=R(e,+b)),c.value&&r.focused){const{selectionEnd:E}=c.value,$=R(n,E);s=y(g($))-y($)}}if(c.value&&c.value.value!==e)if(r.focused){let{selectionStart:g,selectionEnd:b}=c.value;if(c.value.value=e,I(g)&&I(b)){const E=y(e);o?(g-=o,b-=o):s&&(g+=s,b+=s),c.value.setSelectionRange(Math.min(g,E),Math.min(b,E))}}else c.value.value=e;e!==t.modelValue&&i("update:modelValue",e)},X=e=>{e.target.composing||C(e.target.value)},L=()=>{var e;return(e=c.value)==null?void 0:e.blur()},Z=()=>{var e;return(e=c.value)==null?void 0:e.focus()},V=()=>{const e=c.value;t.type==="textarea"&&t.autosize&&e&&He(e,t.autosize)},p=e=>{r.focused=!0,i("focus",e),k(V),f("readonly")&&L()},ee=e=>{r.focused=!1,C(v(),"onBlur"),i("blur",e),!f("readonly")&&(T("onBlur"),k(V),Ne())},W=e=>i("clickInput",e),te=e=>i("clickLeftIcon",e),ne=e=>i("clickRightIcon",e),ae=e=>{H(e),i("update:modelValue",""),i("clear",e)},F=x(()=>{if(typeof t.error=="boolean")return t.error;if(h&&h.props.showError&&r.status==="failed")return!0}),ie=x(()=>{const e=f("labelWidth"),a=f("labelAlign");if(e&&a!=="top")return{width:j(e)}}),re=e=>{e.keyCode===13&&(!(h&&h.props.submitOnEnter)&&t.type!=="textarea"&&H(e),t.type==="search"&&L()),i("keypress",e)},z=()=>t.id||`${d}-input`,le=()=>r.status,oe=()=>{const e=m("control",[f("inputAlign"),{error:F.value,custom:!!l.input,"min-height":t.type==="textarea"&&!t.autosize}]);if(l.input)return u("div",{class:e,onClick:W},[l.input()]);const a={id:z(),ref:c,name:t.name,rows:t.rows!==void 0?+t.rows:void 0,class:e,disabled:f("disabled"),readonly:f("readonly"),autofocus:t.autofocus,placeholder:t.placeholder,autocomplete:t.autocomplete,enterkeyhint:t.enterkeyhint,"aria-labelledby":t.label?`${d}-label`:void 0,onBlur:ee,onFocus:p,onInput:X,onClick:W,onChange:Y,onKeypress:re,onCompositionend:Y,onCompositionstart:qe};return t.type==="textarea"?u("textarea",a,null):u("input",_e(Ke(t.type),a),null)},se=()=>{const e=l["left-icon"];if(t.leftIcon||e)return u("div",{class:m("left-icon"),onClick:te},[e?e():u(P,{name:t.leftIcon,classPrefix:t.iconPrefix},null)])},ce=()=>{const e=l["right-icon"];if(t.rightIcon||e)return u("div",{class:m("right-icon"),onClick:ne},[e?e():u(P,{name:t.rightIcon,classPrefix:t.iconPrefix},null)])},ue=()=>{if(t.showWordLimit&&t.maxlength){const e=y(v());return u("div",{class:m("word-limit")},[u("span",{class:m("word-num")},[e]),Oe("/"),t.maxlength])}},de=()=>{if(h&&h.props.showErrorMessage===!1)return;const e=t.errorMessage||r.validateMessage;if(e){const a=l["error-message"],n=f("errorMessageAlign");return u("div",{class:m("error-message",n)},[a?a({message:e}):e])}},fe=()=>{const e=f("labelWidth"),a=f("labelAlign"),n=f("colon")?":":"";if(l.label)return[l.label(),n];if(t.label)return u("label",{id:`${d}-label`,for:z(),style:a==="top"&&e?{width:j(e)}:void 0},[t.label+n])},ge=()=>[u("div",{class:m("body")},[oe(),U.value&&u(P,{ref:_,name:t.clearIcon,class:m("clear")},null),ce(),l.button&&u("div",{class:m("button")},[l.button()])]),ue(),de()];return Pe({blur:L,focus:Z,validate:N,formValue:O,resetValidation:S,getValidationStatus:le}),Re(De,{customValue:M,resetValidation:S,validateWithTrigger:T}),Me(()=>t.modelValue,()=>{C(v()),S(),T("onChange"),k(V)}),Te(()=>{C(v(),t.formatTrigger),k(V)}),Le("touchstart",ae,{target:x(()=>{var e;return(e=_.value)==null?void 0:e.$el})}),()=>{const e=f("disabled"),a=f("labelAlign"),n=se(),o=()=>{const s=fe();return a==="top"?[n,s].filter(Boolean):s||[]};return u(ze,{size:t.size,class:m({error:F.value,disabled:e,[`label-${a}`]:a}),center:t.center,border:t.border,isLink:t.isLink,clickable:t.clickable,titleStyle:ie.value,valueClass:m("value"),titleClass:[m("label",[a,{required:t.required}]),t.labelClass],arrowDirection:t.arrowDirection},{icon:n&&a!=="top"?()=>n:null,title:o,value:ge,extra:l.extra})}}});const Ze=We(Je);export{Ze as F,Ge as f};