import{u as V}from"./useDefaults-DESCdb0p-CFLjYrdG.js";import{a as D,u as _}from"./useStateClass-BGbSLWFN-BcKQ8Z3i.js";import{u as P}from"./useId-t29UARy6-BH5d2231.js";import{c as W}from"./index-C0p9vHHI-DoOEDIMw.js";import{s as A,I as U,x as q,v as w,az as R,ay as S,H as C,R as h,U as j,l as k,m as K,p as G,q as E,d as H,o as O,D as o,n as Z}from"./index-D02r7Zsc.js";const $=(t,l)=>{if(t===null)return;let a=t;if(l.number&&typeof a=="string"&&a!==""){const e=Number.parseFloat(a);a=Number.isNaN(e)?a:e}return a},T=()=>{};function J(t,l){function a(...e){return new Promise((s,u)=>{Promise.resolve(t(()=>l.apply(this,e),{fn:l,thisArg:this,args:e})).then(s).catch(u)})}return a.cancel=t.cancel,a}function L(t,l={}){let a,e,s=T;const u=d=>{clearTimeout(d),s(),s=T};let m;const x=d=>{const p=h(t),c=h(l.maxWait);return a&&u(a),p<=0||c!==void 0&&c<=0?(e&&(u(e),e=null),Promise.resolve(d())):new Promise((v,b)=>{s=l.rejectOnCancel?b:v,m=d,c&&!e&&(e=setTimeout(()=>{a&&u(a),e=null,v(m())},c)),a=setTimeout(()=>{e&&u(e),e=null,v(d())},p)})};return x.cancel=()=>{a&&u(a),e&&u(e),e=null},x}function Q(t,l=200,a={}){return J(L(l,a),t)}const X=(t,l,a,e)=>{const s=A(0),u=P(()=>t.id,"input"),m=C(()=>t.debounce??0,{nanToZero:!0}),x=C(()=>t.debounceMaxWait??NaN),d=U(S,null)?.(u),p=q(()=>t.state!==void 0?t.state:d?.state.value??null),c=D(()=>t.ariaInvalid,p),v=_(p),b=Q(n=>{a.value=n},()=>e.lazy===!0?0:m.value,{maxWait:()=>e.lazy===!0?NaN:x.value}),g=(n,f=!1,r=!1)=>{e.lazy===!0&&f===!1||(r?a.value=n:b(n))},{focused:B}=W(l,{initialValue:t.autofocus}),z=(n,f,r=!1)=>t.formatter!==void 0&&(!t.lazyFormatter||r)?t.formatter(n,f):n;return w(()=>{l.value&&(l.value.value=a.value?.toString()??"")}),R(()=>{j(()=>{t.autofocus&&(B.value=!0)})}),{input:l,computedId:u,computedAriaInvalid:c,onInput:n=>{const{value:f}=n.target,r=z(f,n);if(n.defaultPrevented){n.preventDefault();return}g(r)},onChange:n=>{const{value:f}=n.target,r=z(f,n);if(n.defaultPrevented){n.preventDefault();return}const F=r;a.value!==F&&g(r,!0)},onBlur:n=>{if(!e.lazy&&!t.lazyFormatter&&!e.trim&&m.value<=0)return;const{value:f}=n.target,r=z(f,n,!0),F=e.trim?r.trim():r,M=F.length!==r.length;b.cancel(),a.value!==F&&g(r,!0,!0),e.trim&&M&&(s.value=s.value+1)},focus:()=>{t.disabled||(B.value=!0)},blur:()=>{t.disabled||(B.value=!1)},forceUpdateKey:s,stateClass:v}},Y=["id","value","name","form","type","disabled","placeholder","required","autocomplete","readonly","min","max","step","list","aria-required","aria-invalid"],ue=k({__name:"BFormInput",props:K({max:{default:void 0},min:{default:void 0},step:{default:void 0},type:{default:"text"},ariaInvalid:{type:[Boolean,String],default:void 0},autocomplete:{default:void 0},autofocus:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},form:{default:void 0},formatter:{type:Function,default:void 0},id:{default:void 0},lazyFormatter:{type:Boolean,default:!1},list:{default:void 0},name:{default:void 0},placeholder:{default:void 0},plaintext:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},required:{type:Boolean,default:!1},size:{default:void 0},state:{type:[Boolean,null],default:void 0},debounce:{default:0},debounceMaxWait:{default:NaN}},{modelValue:{default:""},modelModifiers:{}}),emits:["update:modelValue"],setup(t,{expose:l}){const e=V(t,"BFormInput"),[s,u]=G(t,"modelValue",{set:y=>$(y,u)}),m=E("_input"),{computedId:x,computedAriaInvalid:d,onInput:p,onChange:c,onBlur:v,stateClass:b,focus:g,blur:B,forceUpdateKey:z}=X(e,m,s,u),N=q(()=>{const y=e.type==="range",i=e.type==="color";return[b.value,{"form-range":y,"form-control":i||!e.plaintext&&!y,"form-control-color":i,"form-control-plaintext":e.plaintext&&!y&&!i,[`form-control-${e.size}`]:!!e.size}]});return l({blur:B,element:m,focus:g}),(y,i)=>(O(),H("input",{id:o(x),ref:"_input",key:o(z),value:o(s),class:Z(N.value),name:o(e).name||void 0,form:o(e).form||void 0,type:o(e).type,disabled:o(e).disabled,placeholder:o(e).placeholder,required:o(e).required||void 0,autocomplete:o(e).autocomplete||void 0,readonly:o(e).readonly||o(e).plaintext,min:o(e).min,max:o(e).max,step:o(e).step,list:o(e).type!=="password"?o(e).list:void 0,"aria-required":o(e).required||void 0,"aria-invalid":o(d),onInput:i[0]||(i[0]=(...I)=>o(p)&&o(p)(...I)),onChange:i[1]||(i[1]=(...I)=>o(c)&&o(c)(...I)),onBlur:i[2]||(i[2]=(...I)=>o(v)&&o(v)(...I))},null,42,Y))}});export{ue as _,$ as n,X as u};
