"use strict";const e=require("../../../../common/vendor.js"),t=require("../common/util.js"),n=require("./types.js"),i=require("../common/interceptor.js");Math||u();const u=()=>"../wd-icon/wd-icon.js",s=e.defineComponent({name:"wd-input-number",options:{virtualHost:!0,addGlobalClass:!0,styleIsolation:"shared"},props:n.inputNumberProps,emits:["change","focus","blur","update:modelValue"],setup(n,{emit:u}){const s=n,r=u,o=e.ref(function(){if(!s.updateOnInit)return function(e){if(s.allowNull&&(!t.isDef(e)||""===e))return"";if(!t.isDef(e)||""===e)return s.min;let n=Number(e);if(isNaN(n))return s.min;const i=Number(s.precision);if(!t.isDef(s.precision))return n;return 0===i?Number(n.toFixed(0)):n.toFixed(i)}(s.modelValue);const e=h(s.modelValue);t.isEqual(String(e),String(s.modelValue))||r("update:modelValue",e);return e}());let a=null;const l=e.computed((()=>{const e=m(o.value);return s.disabled||e<=s.min||v(e,-s.step)<s.min})),c=e.computed((()=>{const e=m(o.value);return s.disabled||e>=s.max||v(e,s.step)>s.max}));function d(e){if(!t.isDef(e))return 0;const n=e.toString(),i=n.indexOf(".");return-1===i?0:n.length-i-1}function p(e){const t=Number(s.precision);return Math.round(e*Math.pow(10,t))/Math.pow(10,t)}function m(e){if(s.allowNull&&(!t.isDef(e)||""===e))return NaN;if(!t.isDef(e)||""===e)return s.min;let n=String(e);if(n.endsWith(".")&&(n=n.slice(0,-1)),n.startsWith(".")&&(n="0"+n),n.startsWith("-.")&&(n="-0"+n.substring(1)),"-"===n||""===n)return s.min;let i=Number(n);return isNaN(i)&&(i=s.min),f(i)}function f(e){let n=e;if(s.stepStrictly){const e=d(s.step),t=Math.pow(10,e);n=Math.round(n/s.step)*t*s.step/t}return n=s.stepStrictly?function(e,t,n){if(e>=t&&e<=n)return e;const i=d(s.step),u=Math.pow(10,i);if(e<t){const e=p(Math.ceil(t*u/(s.step*u))*s.step*u/u);if(e>n){return p(Math.floor(n*u/(s.step*u))*s.step*u/u)}return e}if(e>n){const e=p(Math.floor(n*u/(s.step*u))*s.step*u/u);if(e<t){return p(Math.ceil(t*u/(s.step*u))*s.step*u/u)}return e}return e}(n,s.min,s.max):Math.min(Math.max(n,s.min),s.max),t.isDef(s.precision)&&(n=p(n)),n}function h(e){if(s.allowNull&&(!t.isDef(e)||""===e))return"";const n=m(e),i=Number(s.precision);return t.isDef(s.precision)?0===i?Number(n.toFixed(0)):n.toFixed(i):n}function b(e){if(s.allowNull&&(!t.isDef(e)||""===e)){if(t.isEqual("",String(s.modelValue)))return void(o.value="");const e=()=>{o.value="",r("update:modelValue",""),r("change",{value:""})};return void i.callInterceptor(s.beforeChange,{args:[""],done:e})}const n=m(e),u=h(e);if(t.isEqual(String(n),String(s.modelValue)))return void(o.value=u);i.callInterceptor(s.beforeChange,{args:[n],done:()=>{o.value=u,r("update:modelValue",n),r("change",{value:n})}})}function v(e,t){const n=Number(e);if(isNaN(n))return f(s.min);const i=Math.max(d(n),d(t)),u=Math.pow(10,i);return f((n*u+t*u)/u)}function g(e){const t="add"===e?s.step:-s.step;if(t<0&&(l.value||s.disableMinus)||t>0&&(c.value||s.disablePlus))return;b(v(o.value,t))}function w(t){const n=t.detail.value||"";o.value=n,e.nextTick$1((()=>{if(""===n)return o.value="",void(s.immediateChange&&s.allowNull&&b(""));const e=function(e){if(!e)return"";let t=e.replace(/[^\d.-]/g,"");const n=t.startsWith("-");if(t=t.replace(/-/g,""),n&&(t="-"+t),Number(s.precision)>0){const e=t.split(".");e.length>2&&(t=e[0]+"."+e.slice(1).join(""))}else t=t.split(".")[0];return t.startsWith(".")?"0"+t:t.startsWith("-.")?"-0"+t.substring(1):t}(n);Number(s.precision)>0&&function(e){if(!e)return!1;const t=String(e);return t.endsWith(".")||t.startsWith(".")||t.startsWith("-.")||"-"===t||Number(s.precision)>0&&-1===t.indexOf(".")}(e)?o.value=e:(o.value=e,s.immediateChange&&b(e))}))}function N(e){const t=e.detail.value||"";b(t),r("blur",{value:t})}function x(e){r("focus",e.detail)}function M(e){W(),a=setTimeout((()=>{g(e),M(e)}),250)}function S(e){s.longPress&&(W(),a=setTimeout((()=>{g(e),M(e)}),600))}function _(){s.longPress&&W()}function W(){a&&(clearTimeout(a),a=null)}return e.watch((()=>s.modelValue),(e=>{o.value=h(e)})),e.watch([()=>s.max,()=>s.min,()=>s.precision],(()=>{const e=m(o.value);o.value=h(e)})),(t,n)=>e.e({a:e.p({name:"decrease","custom-class":"wd-input-number__action-icon"}),b:e.n("wd-input-number__action "+(l.value||t.disableMinus?"is-disabled":"")),c:e.o((e=>g("sub"))),d:e.o((e=>S("sub"))),e:e.o(_),f:!t.withoutInput},t.withoutInput?{}:{g:e.s(""+(t.inputWidth?"width: "+t.inputWidth:"")),h:t.inputType,i:t.precision?"decimal":"numeric",j:t.disabled||t.disableInput,k:String(o.value),l:t.placeholder,m:t.adjustPosition,n:e.o(w),o:e.o(x),p:e.o(N),q:e.o((()=>{}))},{r:e.p({name:"add","custom-class":"wd-input-number__action-icon"}),s:e.n("wd-input-number__action "+(c.value||t.disablePlus?"is-disabled":"")),t:e.o((e=>g("add"))),v:e.o((e=>S("add"))),w:e.o(_),x:e.n(`wd-input-number ${t.customClass} ${t.disabled?"is-disabled":""} ${t.withoutInput?"is-without-input":""}`),y:e.s(t.customStyle)})}}),r=e._export_sfc(s,[["__scopeId","data-v-5a101a5e"]]);wx.createComponent(r);
