import{A as J,aa as c,G as g,E as h,d as Q,S as D,V as f,a1 as F,bd as X,a2 as w,a_ as Y,j as v,a5 as I,aE as N,a7 as A,aT as R,aN as k,L as z,W as Z,aO as p,ap as y,aB as ee,be as te,N as ae}from"./index.3bfa6a0e.js";const[ne,S]=J("stepper"),le=200,ie=600,P=(t,u)=>String(t)===String(u),ue={min:c(1),max:c(1/0),name:c(""),step:c(1),theme:String,integer:Boolean,disabled:Boolean,showPlus:g,showMinus:g,showInput:g,longPress:g,allowEmpty:Boolean,modelValue:h,inputWidth:h,buttonSize:h,placeholder:String,disablePlus:Boolean,disableMinus:Boolean,disableInput:Boolean,beforeChange:Function,defaultValue:c(1),decimalLength:h};var se=Q({name:ne,props:ue,emits:["plus","blur","minus","focus","change","overlimit","update:modelValue"],setup(t,{emit:u}){const o=e=>{const{min:a,max:i,allowEmpty:b,decimalLength:l}=t;return b&&e===""||(e=k(String(e),!t.integer),e=e===""?0:+e,e=Number.isNaN(e)?+a:e,e=Math.max(Math.min(+i,e),+a),z(l)&&(e=e.toFixed(+l))),e},G=()=>{var e;const a=(e=t.modelValue)!=null?e:t.defaultValue,i=o(a);return P(i,t.modelValue)||u("update:modelValue",i),i};let s;const x=D(),n=D(G()),d=f(()=>t.disabled||t.disableMinus||n.value<=+t.min),r=f(()=>t.disabled||t.disablePlus||n.value>=+t.max),O=f(()=>({width:F(t.inputWidth),height:F(t.buttonSize)})),E=f(()=>X(t.buttonSize)),W=()=>{const e=o(n.value);P(e,n.value)||(n.value=e)},B=e=>{t.beforeChange?ee(t.beforeChange,{args:[e],done(){n.value=e}}):n.value=e},T=()=>{if(s==="plus"&&r.value||s==="minus"&&d.value){u("overlimit",s);return}const e=s==="minus"?-t.step:+t.step,a=o(te(+n.value,e));B(a),u(s)},$=e=>{const a=e.target,{value:i}=a,{decimalLength:b}=t;let l=k(String(i),!t.integer);if(z(b)&&l.includes(".")){const M=l.split(".");l=`${M[0]}.${M[1].slice(0,+b)}`}t.beforeChange?a.value=String(n.value):P(i,l)||(a.value=l);const U=l===String(+l);B(U?+l:l)},j=e=>{var a;t.disableInput?(a=x.value)==null||a.blur():u("focus",e)},q=e=>{const a=e.target,i=o(a.value);a.value=String(i),n.value=i,Z(()=>{u("blur",e),p()})};let V,m;const C=()=>{m=setTimeout(()=>{T(),C()},le)},H=()=>{t.longPress&&(V=!1,clearTimeout(m),m=setTimeout(()=>{V=!0,T(),C()},ie))},L=e=>{t.longPress&&(clearTimeout(m),V&&y(e))},K=e=>{t.disableInput&&y(e)},_=e=>({onClick:a=>{y(a),s=e,T()},onTouchstart:()=>{s=e,H()},onTouchend:L,onTouchcancel:L});return w(()=>[t.max,t.min,t.integer,t.decimalLength],W),w(()=>t.modelValue,e=>{P(e,n.value)||(n.value=o(e))}),w(n,e=>{u("update:modelValue",e),u("change",e,{name:t.name})}),Y(()=>t.modelValue),()=>v("div",{role:"group",class:S([t.theme])},[I(v("button",A({type:"button",style:E.value,class:[S("minus",{disabled:d.value}),{[R]:!d.value}],"aria-disabled":d.value||void 0},_("minus")),null),[[N,t.showMinus]]),I(v("input",{ref:x,type:t.integer?"tel":"text",role:"spinbutton",class:S("input"),value:n.value,style:O.value,disabled:t.disabled,readonly:t.disableInput,inputmode:t.integer?"numeric":"decimal",placeholder:t.placeholder,"aria-valuemax":t.max,"aria-valuemin":t.min,"aria-valuenow":n.value,onBlur:q,onInput:$,onFocus:j,onMousedown:K},null),[[N,t.showInput]]),I(v("button",A({type:"button",style:E.value,class:[S("plus",{disabled:r.value}),{[R]:!r.value}],"aria-disabled":r.value||void 0},_("plus")),null),[[N,t.showPlus]])])}});const ce=ae(se);export{ce as S};
