import{d as g,k as m,B as x,o as N,y as B,n as F,r as I}from"./index-CcdGGfCj.js";import{_ as M}from"./_plugin-vue_export-helper-DlAUqK2U.js";const k=g({__name:"AdminNumberInput",props:{modelValue:{default:null},min:{},max:{},precision:{default:2},disabled:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},placeholder:{default:""}},emits:["update:modelValue"],setup(t,{emit:p}){const l=t,u=p,n=m(r(l.modelValue)),i=m(!1);x(()=>l.modelValue,e=>{i.value||(n.value=r(e))});function r(e){if(e==null||e==="")return"";const a=Number(e);if(!Number.isFinite(a))return"";const o=10**l.precision;return String(Math.round(a*o)/o)}function f(e){const a=e.replace(/,/g,".").replace(/[^\d.-]/g,""),o=a.startsWith("-"),s=a.replace(/-/g,""),[d="",...h]=s.split("."),c=o?"-":"";if(l.precision===0)return c+d;const y=s.includes("."),V=h.join("").slice(0,l.precision);return c+d+(y?`.${V}`:"")}function v(e){if(n.value=f(e),n.value===""||n.value==="-"||n.value==="."||n.value==="-."){u("update:modelValue",null);return}const a=Number(n.value);Number.isFinite(a)&&u("update:modelValue",a)}function b(){if(i.value=!1,n.value===""||n.value==="-"||n.value==="."||n.value==="-."){n.value="",u("update:modelValue",null);return}let e=Number(n.value);if(!Number.isFinite(e)){n.value=r(l.modelValue);return}l.min!==void 0&&(e=Math.max(l.min,e)),l.max!==void 0&&(e=Math.min(l.max,e));const a=10**l.precision;e=Math.round(e*a)/a,n.value=String(e),u("update:modelValue",e)}return(e,a)=>{const o=I("el-input");return N(),B(o,{class:F(["admin-number-input",{"is-readonly":t.readonly}]),"model-value":n.value,type:"text",inputmode:t.precision===0?"numeric":"decimal",disabled:t.disabled,readonly:t.readonly,placeholder:t.placeholder,onFocus:a[0]||(a[0]=s=>i.value=!0),onInput:v,onBlur:b},null,8,["class","model-value","inputmode","disabled","readonly","placeholder"])}}}),C=M(k,[["__scopeId","data-v-d9349eae"]]);export{C as A};
