import{M as g}from"./lucide-vue-next-DqYmV2Wg.js";import{P as B}from"./ruler-IYY3v2Di.js";import{v as u,x as a,E as k,B as o,D as i,l as c,p as b,z as p,s as S,f}from"./x-CuOWXDIc.js";const w={class:"form-group"},C={key:0,class:"form-group__label"},M={key:0,class:"form-group__required"},q={class:"number-field"},z=["disabled"],D={class:"number-field__input-wrapper"},I={key:0,class:"number-field__prefix"},E=["value","placeholder","disabled"],F={key:1,class:"number-field__suffix"},P=["disabled"],T={key:1,class:"form-group__error"},$={key:2,class:"form-group__hint"},H={__name:"NumberField",props:{modelValue:{type:[Number,String],default:null},label:{type:String,default:""},placeholder:{type:String,default:""},hint:{type:String,default:""},error:{type:String,default:""},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},size:{type:String,default:"md"},min:{type:Number,default:null},max:{type:Number,default:null},step:{type:Number,default:1},showButtons:{type:Boolean,default:!0},prefix:{type:String,default:""},suffix:{type:String,default:""}},emits:["update:modelValue","focus","blur"],setup(e,{emit:h}){const l=e,s=h,r=f(()=>{const n=Number(l.modelValue);return isNaN(n)?null:n}),y=f(()=>l.min===null||r.value!==null&&r.value>l.min),x=f(()=>l.max===null||r.value!==null&&r.value<l.max);function m(n){let t=n;return l.min!==null&&(t=Math.max(t,l.min)),l.max!==null&&(t=Math.min(t,l.max)),t}function N(n){const t=n.target.value;if(t===""||t==="-"){s("update:modelValue",t);return}const d=Number(t);isNaN(d)||s("update:modelValue",d)}function v(n){if(l.modelValue!==""&&l.modelValue!==null){const t=Number(l.modelValue);isNaN(t)||s("update:modelValue",m(t))}s("blur",n)}function V(){const n=r.value??0;s("update:modelValue",m(n+l.step))}function _(){const n=r.value??0;s("update:modelValue",m(n-l.step))}return(n,t)=>(u(),a("div",w,[e.label?(u(),a("label",C,[k(o(e.label)+" ",1),e.required?(u(),a("span",M,"*")):i("",!0)])):i("",!0),c("div",q,[e.showButtons?(u(),a("button",{key:0,type:"button",class:"number-field__btn number-field__btn--decrement",disabled:e.disabled||!y.value,onClick:_},[b(p(g),{class:"icon-md"})],8,z)):i("",!0),c("div",D,[e.prefix?(u(),a("span",I,o(e.prefix),1)):i("",!0),c("input",{type:"text",inputmode:"numeric",value:e.modelValue,placeholder:e.placeholder,disabled:e.disabled,class:S(["number-field__input",e.error?"number-field__input--error":"",e.showButtons?"":"number-field__input--no-buttons",e.prefix?"number-field__input--has-prefix":"",e.suffix?"number-field__input--has-suffix":""]),onInput:N,onBlur:v,onFocus:t[0]||(t[0]=d=>n.$emit("focus",d))},null,42,E),e.suffix?(u(),a("span",F,o(e.suffix),1)):i("",!0)]),e.showButtons?(u(),a("button",{key:1,type:"button",class:"number-field__btn number-field__btn--increment",disabled:e.disabled||!x.value,onClick:V},[b(p(B),{class:"icon-md"})],8,P)):i("",!0)]),e.error?(u(),a("p",T,o(e.error),1)):e.hint?(u(),a("p",$,o(e.hint),1)):i("",!0)]))}};export{H as _};
