<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 genusInputRef = ref(null);
const genusFormData = reactive({});

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

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

<template>
    <FormModelPopup
        url-create="genera"
        model="itemGenus"
        :title="t('New genus')"
        :form-initial-data="genusFormData"
        @on-data-saved="onDataSaved"
    >
        <template #form-inputs="{ data }">
            <VnRow>
                <VnInput
                    ref="genusInputRef"
                    :label="t('Latin genus name')"
                    v-model="data.name"
                    :required="true"
                />
            </VnRow>
        </template>
    </FormModelPopup>
</template>

<i18n>
es:
    New genus: Nuevo genus
    Latin genus name: Nombre del genus en latín
</i18n>
