<script setup>
import { reactive, ref, onMounted, nextTick } from 'vue';
import { useI18n } from 'vue-i18n';
import VnInput from 'src/components/common/VnInput.vue';

import VnRow from 'components/ui/VnRow.vue';
import FormModelPopup from 'components/FormModelPopup.vue';

const { t } = useI18n();
const emit = defineEmits(['onDataSaved']);

const nameInputRef = ref(null);
const serviceFormData = reactive({});

const onDataSaved = (formData, requestResponse) => {
    emit('onDataSaved', formData, requestResponse);
};

onMounted(async () => {
    await nextTick();
    nameInputRef.value.focus();
});
</script>

<template>
    <FormModelPopup
        url-create="TicketServiceTypes"
        model="TicketServiceType"
        :title="t('New service type')"
        :form-initial-data="serviceFormData"
        @on-data-saved="onDataSaved"
    >
        <template #form-inputs="{ data }">
            <VnRow>
                <VnInput
                    ref="nameInputRef"
                    :label="t('service.description')"
                    v-model="data.name"
                    :required="true"
                />
            </VnRow>
        </template>
    </FormModelPopup>
</template>

<i18n>
es:
    New service type: Nuevo tipo de servicio
</i18n>
