<script setup>
import VnInput from 'src/components/common/VnInput.vue';

defineProps({
    step: { type: Number, default: 0.01 },
    decimalPlaces: { type: Number, default: 2 },
    positive: { type: Boolean, default: true },
});

const model = defineModel({ type: [Number, String] });
</script>
<template>
    <VnInput
        v-bind="$attrs"
        v-model.number="model"
        type="number"
        :step="step"
        @input="
            (evt) => {
                const val = evt.target.value;
                if (positive && val < 0) return (model = 0);
                const [, decimal] = val.split('.');
                if (val && decimal?.length > decimalPlaces)
                    model = parseFloat(val).toFixed(decimalPlaces);
            }
        "
    />
</template>
