import{InputView}from"./base.mjs";import{isEmpty}from"../../../base/helpers.mjs";class NumberInputView extends InputView{static min=null;static max=null;static step=1;static inputType="number";static bindMouseWheel=!0;static useMouseWheelAltKey=!0;constructor(t,e,s){super(t,e,s),this.minValue=isEmpty(s)||isEmpty(s.min)?this.constructor.min:s.min,this.maxValue=isEmpty(s)||isEmpty(s.max)?this.constructor.max:s.max,this.stepValue=isEmpty(s)||isEmpty(s.step)?this.constructor.step:s.step}get precision(){if(isEmpty(this.stepValue)||this.stepValue>=1||this.stepValue<0)return 0;let t=`${this.stepValue}`.split(".");return t.length<2?0:t[1].length}setMin(t){this.minValue=t,void 0!==this.node&&this.node.attr("min",this.minValue)}setMax(t){this.maxValue=t,void 0!==this.node&&this.node.attr("max",this.maxValue)}setStep(t){this.stepValue=t,void 0!==this.node&&this.node.attr("step",this.stepValue)}checkValue(){let t=this.getValue();this.value;if(!isEmpty(this.minValue)&&t<this.minValue)this.setValue(this.minValue,!1);else if(!isEmpty(this.maxValue)&&t>this.maxValue)this.setValue(this.maxValue,!1);else if(!isEmpty(this.stepValue)){let e=this.stepValue*Math.pow(10,this.precision),s=t*Math.pow(10,this.precision),i=s%e;if(0!==i){let t=parseFloat(((s-i)/Math.pow(10,this.precision)).toFixed(this.precision));this.setValue(t,!1)}}}changed(){this.checkValue(),super.changed()}getValue(t){let e=super.getValue(t);return isEmpty(this.stepValue)||this.stepValue>=1?parseInt(e):parseFloat(e)}async build(){let t=await super.build();return isEmpty(this.minValue)||t.attr("min",this.minValue),isEmpty(this.maxValue)||t.attr("max",this.maxValue),isEmpty(this.stepValue)||t.attr("step",this.stepValue),this.constructor.bindMouseWheel&&t.on("mousewheel",(t=>{if(this.constructor.useMouseWheelAltKey&&!t.altKey)return;t.preventDefault(),t.stopPropagation();let e=isEmpty(this.stepValue)?1:this.stepValue;t.deltaY>0&&(e*=-1),this.setValue(this.value+e)})),t}}class FloatInputView extends NumberInputView{static step="any"}class DateTimeInputView extends NumberInputView{static inputType="datetime-local";static step=null;constructor(t,e,s){super(t,e,s),this.value instanceof Date&&(this.value=this.value.toISOString().split(".")[0])}setValue(t){super.setValue(t),this.value instanceof Date&&(this.value=this.value.toISOString().split(".")[0])}getValue(t){return new Date(this.value)}}class DateInputView extends NumberInputView{static inputType="date";static step=null;constructor(t,e,s){super(t,e,s),this.value instanceof Date&&(this.value=this.value.toISOString().split("T")[0])}setValue(t){if(t instanceof Date)try{t=t.toISOString().split("T")[0]}catch(e){t=null}super.setValue(t)}getValue(t){return void 0!==this.node?new Date(this.node.val()):new Date(this.value)}}class TimeInputView extends NumberInputView{static step=null;static inputType="time"}export{NumberInputView,FloatInputView,DateInputView,TimeInputView,DateTimeInputView};
