<script setup>
import { useRouter, useRoute } from 'vue-router';
import { useForm } from '@Services/Api';
import { apiTo, transl, viewTo } from './Module';

import IconButton      from '@Holos/Button/Icon.vue'
import PageHeader      from '@Holos/PageHeader.vue';
import FormCertification from './FormCertification.vue';

/** Definidores */
const router = useRouter();
const route = useRoute();

/** Propiedades */
const form = useForm({
    name: '',
    description: '',
    institution: '',
    date_obtained: '',
    date_expiration: '',
    number: '',
    user_id: route.params.id || '',
});

/** Métodos */
function submit() {
    form.post(apiTo('store-certificate'), {
        onSuccess: () => {
            Notify.success(Lang('register.create.onSuccess'))
            router.push(viewTo({ name: 'index' }));
        }
    })
}
</script>

<template>
    <PageHeader
        :title="transl('create.certification.title')"
    >
        <RouterLink :to="viewTo({ name: 'index' })">
            <IconButton
                class="text-white"
                icon="arrow_back"
                :title="$t('return')"
                filled
            />
        </RouterLink>
    </PageHeader>
    
    <div class="w-full pb-2">
        <p class="text-justify text-sm" v-text="transl('create.certification.description')" />
    </div>
    
    <FormCertification
        :form="form"
        @submit="submit"
    />
</template>