import{S as re,g as f,a2 as se,J as $,L as ie,K as ue,l as de,p as ce,aa as pe,r as y,q as fe,s as me,M as R,h as w,o as u,t as r,u as l,w as U,b as D,c as V,z as p,Y as be,v as C,aj as ge,x as he,C as ve}from"./index-CdEV5Lsj.js";import{b as z}from"./index-DruWBKkm.js";import{_ as ye}from"./ULabel.vue_vue_type_script_setup_true_lang-DmdMPZfT.js";function we(I,A,d={childList:!0,attributes:!0,characterData:!0}){if(re)return;const t=new MutationObserver(A),o=f(()=>se(I));return $(()=>{o.value&&(Array.isArray(o.value)?o.value.forEach(c=>{t.observe(c,d)}):t.observe(o.value,d))}),ie(o,()=>{if(o.value){if(Array.isArray(o.value)){o.value.forEach(c=>{t.observe(c,d)});return}t.observe(o.value,d)}},{deep:!0}),ue(()=>{t.disconnect()}),{observer:t}}const N={inputLabel:"{ULabel}",wrapper:{base:`
      border rounded-dynamic border-gray-300 relative flex w-full bg-white transition
      hover:border-gray-400 hover:focus-within:border-brand-600 focus-within:border-brand-600
      focus-within:outline focus-within:outline-dynamic-sm focus-within:outline-brand-600
    `,variants:{error:{true:"!border-red-600 focus-within:outline-red-600"},disabled:{true:"!border-gray-300 focus-within:outline-0 bg-gray-100"}}},inputIcon:{base:"{UIcon}",defaults:{size:{sm:"xs",md:"sm",lg:"md"}}},leftIcon:"{UIcon} {>inputIcon}",rightIcon:"{UIcon} {>inputIcon}",passwordIcon:"{UIcon} {>inputIcon}",passwordIconWrapper:"flex items-center justify-end whitespace-nowrap pr-2.5 gap-1 rounded-inherit rounded-l-none",leftSlot:"pl-2.5 flex items-center",rightSlot:"pr-2.5 flex items-center",input:{base:`
      block w-full py-2 px-3 font-normal !leading-none bg-transparent
      border-none rounded-inherit transition focus:ring-0
      placeholder:font-normal placeholder-gray-400
      disabled:text-gray-700 disabled:cursor-not-allowed
    `,variants:{size:{sm:"text-xs placeholder:text-xs placeholder:font-normal",md:"text-sm placeholder:text-sm placeholder:font-normal",lg:"text-base placeholder:text-base placeholder:font-normal"},error:{true:"placeholder:text-red-300"},typePassword:{true:"tracking-widest [-webkit-text-security:disc]"}},compoundVariants:[{labelAlign:"topInside",label:!0,size:"sm",class:"pt-5"},{labelAlign:"topInside",label:!0,size:"md",class:"pt-6"},{labelAlign:"topInside",label:!0,size:"lg",class:"pt-7"}]},defaults:{size:"md",type:"text",inputmode:"text",labelAlign:"topInside",validationRule:"",readonly:!1,disabled:!1,noAutocomplete:!1,passwordVisibleIcon:"visibility-fill",passwordHiddenIcon:"visibility_off-fill"}},Ie="UInput",Ae=["for"],ke=["id","placeholder","type","readonly","disabled","maxlength","inputmode","data-test"],Se=["for"],ze=de({inheritAttrs:!1,__name:"UInput",props:ce({modelValue:{},label:{},labelAlign:{},placeholder:{},description:{},error:{},size:{},leftIcon:{},rightIcon:{},maxLength:{},validationRule:{},type:{},inputmode:{},readonly:{type:Boolean},disabled:{type:Boolean},noAutocomplete:{type:Boolean},id:{},config:{},dataTest:{}},{...ve(N,Ie),modelValue:"",label:"",placeholder:""}),emits:["update:modelValue","change","click","focus","mousedown","blur","input","copy","paste"],setup(I,{expose:A,emit:d}){const t=I,o=d,c={integer:/\d*/g,number:/\d*\.?\d*/g,string:/[a-zA-Z]+/g,stringAndNumber:/[a-zA-Z0-9]+/g,symbol:/\D/g},M=pe(),m=y(!1),s=y(null),h=y(null),v=y(null),k=f(()=>t.type==="password"),S=f({get:()=>t.modelValue,set:e=>o("update:modelValue",e)}),b=t.id||fe(),T=f(()=>m.value||t.noAutocomplete?"text":t.type),x=f(()=>m.value?P.value.defaults.passwordVisibleIcon||"":P.value.defaults.passwordHiddenIcon||"");$(()=>{g(!0),B()});function O(e){const n=e.target;if(!n)return;let a=n.value;if(t.validationRule){const i=document.querySelector(`#${b}`);if(!i)return;a=c[t.validationRule]?E(a,c[t.validationRule]):E(a,t.validationRule),i.value=a}o("input",a)}function W(e){o("change",e)}function j(e){g(!1),o("click",e)}function q(e){g(!1),o("focus",e)}function F(e){g(!0),o("blur",e)}function H(e){g(!1),o("mousedown",e)}function Z(e){o("paste",e)}function G(e){o("copy",e)}function J(){m.value=!m.value}function g(e){t.noAutocomplete&&!t.readonly&&s.value&&(e?s.value.setAttribute("readonly","readonly"):s.value.removeAttribute("readonly"))}function E(e,n){const a=new RegExp(n,"ig"),i=String(e).match(a);return i?i.join(""):""}we(h,e=>e.forEach(B),{childList:!0,characterData:!0,subtree:!0});function B(){var n,a;const e=!R(M.left)&&!t.leftIcon;if(!(t.labelAlign==="top"||e)&&h.value&&s.value&&(n=v.value)!=null&&n.labelElement){const i=h.value.getBoundingClientRect().width,ne=parseFloat(getComputedStyle(s.value).paddingLeft);(a=v.value)!=null&&a.labelElement&&(v.value.labelElement.style.left=`${i+ne}px`)}}A({inputRef:s});const K=f(()=>({error:!!t.error&&!t.disabled,label:!!t.label,typePassword:!!(S.value&&!m.value&&k.value)})),{getDataTest:L,config:P,inputAttrs:X,wrapperAttrs:Y,inputLabelAttrs:Q,passwordIconAttrs:_,leftIconAttrs:ee,leftSlotAttrs:te,rightIconAttrs:oe,rightSlotAttrs:le,passwordIconWrapperAttrs:ae}=me(N,K);return(e,n)=>(u(),w(ye,r({ref_key:"labelComponentRef",ref:v,for:l(b),label:e.label,description:e.description,disabled:e.disabled,error:e.error,size:e.size,align:e.labelAlign,centred:"",interactive:""},l(Q)),{label:U(()=>[C(e.$slots,"label",{label:e.label})]),default:U(()=>[D("label",r({for:l(b)},l(Y)),[l(R)(e.$slots.left)||e.leftIcon?(u(),V("span",r({key:0},l(te),{ref_key:"leftSlotWrapperRef",ref:h}),[C(e.$slots,"left",{iconName:e.leftIcon},()=>[e.leftIcon?(u(),w(z,r({key:0,internal:"",color:"gray",name:e.leftIcon},l(ee)),null,16,["name"])):p("",!0)])],16)):p("",!0),be(D("input",r({id:l(b),ref_key:"inputRef",ref:s,"onUpdate:modelValue":n[0]||(n[0]=a=>S.value=a),placeholder:e.placeholder,type:T.value,readonly:e.readonly,disabled:e.disabled,maxlength:e.maxLength,inputmode:e.inputmode},l(X),{"data-test":l(L)(),onFocus:q,onBlur:F,onInput:O,onChange:W,onMousedown:H,onClick:j,onPaste:Z,onCopy:G}),null,16,ke),[[ge,S.value]]),k.value?(u(),V("label",r({key:1},l(ae),{for:l(b)}),[k.value?(u(),w(z,r({key:0,name:x.value,color:"gray",interactive:"",internal:""},l(_),{"data-test":l(L)("password-icon"),onClick:J}),null,16,["name","data-test"])):p("",!0)],16,Se)):p("",!0),l(R)(e.$slots.right)||e.rightIcon?(u(),V("div",he(r({key:2},l(le))),[C(e.$slots,"right",{iconName:e.rightIcon},()=>[e.rightIcon?(u(),w(z,r({key:0,internal:"",color:"gray",name:e.rightIcon},l(oe)),null,16,["name"])):p("",!0)])],16)):p("",!0)],16,Ae)]),_:3},16,["for","label","description","disabled","error","size","align"]))}});export{ze as _,we as u};
