<template>
    <v-text type="date" :required="field.required" :name="field.key" :label="field.name" :id="innerId" :hint="field.hint" v-model="inner" :max-today="field.max_today"></v-text>
</template>

<script setup>
import {computed} from 'vue';
import VText from './VText.vue';

const emit = defineEmits(['update:modelValue']);
const props = defineProps({
    modelValue: {
        required: true,
        validator: (value) => value === null || typeof value === 'string',
    },
    field: {
        required: true,
        validator: (value) =>
            hasKeys(value, [...globalFieldRules(), 'required', 'max_today']) &&
            typeof value.required === 'boolean' &&
            typeof value.max_today === 'boolean' &&
            typeof value.key === 'string' &&
            value.key.length > 0 &&
            typeof value.name === 'string' &&
            value.name.length > 0 &&
            hasKeys(value.columns, ['mobile', 'desktop', 'tablet']),
    },
    id: {
        required: false,
    },
});

const innerId = computed(() => (props.id ? props.id : props.field.key));

const inner = computed({
    get: () => props.modelValue,
    set: (v) => emit('update:modelValue', v),
});
</script>
