import{E as Y,ab as c,H as f,G as g,d as j,U as F,W as h,a2 as D,be as J,a3 as V,a$ as Q,i as v,a6 as I,aF as y,a8 as R,aY as k,aN as z,M as A,X as Z,aP as p,aq as N,aC as ee,bf as te,O as ae}from"./index.7994470a.js";const[ne,S]=Y("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:f,showMinus:f,showInput:f,longPress:f,allowEmpty:Boolean,modelValue:g,inputWidth:g,buttonSize:g,placeholder:String,disablePlus:Boolean,disableMinus:Boolean,disableInput:Boolean,beforeChange:Function,defaultValue:c(1),decimalLength:g};var se=j({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=z(String(e),!t.integer),e=e===""?0:+e,e=Number.isNaN(e)?+a:e,e=Math.max(Math.min(+i,e),+a),A(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=F(),n=F(G()),d=h(()=>t.disabled||t.disableMinus||n.value<=+t.min),r=h(()=>t.disabled||t.disablePlus||n.value>=+t.max),O=h(()=>({width:D(t.inputWidth),height:D(t.buttonSize)})),C=h(()=>J(t.buttonSize)),W=()=>{const e=o(n.value);P(e,n.value)||(n.value=e)},E=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));E(a),u(s)},$=e=>{const a=e.target,{value:i}=a,{decimalLength:b}=t;let l=z(String(i),!t.integer);if(A(b)&&l.includes(".")){const _=l.split(".");l=`${_[0]}.${_[1].slice(0,+b)}`}t.beforeChange?a.value=String(n.value):P(i,l)||(a.value=l);const X=l===String(+l);E(X?+l:l)},q=e=>{var a;t.disableInput?(a=x.value)==null||a.blur():u("focus",e)},H=e=>{const a=e.target,i=o(a.value);a.value=String(i),n.value=i,Z(()=>{u("blur",e),p()})};let w,m;const M=()=>{m=setTimeout(()=>{T(),M()},le)},U=()=>{t.longPress&&(w=!1,clearTimeout(m),m=setTimeout(()=>{w=!0,T(),M()},ie))},B=e=>{t.longPress&&(clearTimeout(m),w&&N(e))},K=e=>{t.disableInput&&N(e)},L=e=>({onClick:a=>{N(a),s=e,T()},onTouchstart:()=>{s=e,U()},onTouchend:B,onTouchcancel:B});return V(()=>[t.max,t.min,t.integer,t.decimalLength],W),V(()=>t.modelValue,e=>{P(e,n.value)||(n.value=o(e))}),V(n,e=>{u("update:modelValue",e),u("change",e,{name:t.name})}),Q(()=>t.modelValue),()=>v("div",{role:"group",class:S([t.theme])},[I(v("button",R({type:"button",style:C.value,class:[S("minus",{disabled:d.value}),{[k]:!d.value}],"aria-disabled":d.value||void 0},L("minus")),null),[[y,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:H,onInput:$,onFocus:q,onMousedown:K},null),[[y,t.showInput]]),I(v("button",R({type:"button",style:C.value,class:[S("plus",{disabled:r.value}),{[k]:!r.value}],"aria-disabled":r.value||void 0},L("plus")),null),[[y,t.showPlus]])])}});const ce=ae(se);export{ce as S};
