<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
import { Head, useForm } from '@inertiajs/vue3';
import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';

const props = defineProps({
    agent: Object,
    templates: Array,
});

const form = useForm({
    agent_id: props.agent.id,
    template_id: '',
    departure_date: '',
});

const submit = () => {
    form.post(route('offboarding.store'));
};
</script>

<template>
    <Head title="Nouvel Offboarding" />

    <AuthenticatedLayout>
        <template #header>
            <h2 class="text-xl font-semibold leading-tight text-gray-800 dark:text-gray-200">
                Préparer le départ de {{ agent.first_name }} {{ agent.last_name }}
            </h2>
        </template>

        <div class="py-12">
            <div class="mx-auto max-w-7xl sm:px-6 lg:px-8">
                <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg dark:bg-gray-800 p-8 max-w-2xl mx-auto">
                    <form @submit.prevent="submit" class="space-y-6">
                        <div>
                            <InputLabel for="departure_date" value="Date effective du départ" />
                            <TextInput id="departure_date" type="date" class="mt-1 block w-full" v-model="form.departure_date" required />
                            <InputError class="mt-2" :message="form.errors.departure_date" />
                        </div>

                        <div>
                            <InputLabel for="template_id" value="Template de sortie (Optionnel)" />
                            <select id="template_id" v-model="form.template_id" class="mt-1 block w-full border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 rounded-md shadow-sm">
                                <option value="">Standard (Sans template)</option>
                                <option v-for="t in templates" :key="t.id" :value="t.id">{{ t.name }}</option>
                            </select>
                            <InputError class="mt-2" :message="form.errors.template_id" />
                        </div>

                        <div class="flex items-center justify-end">
                            <PrimaryButton class="bg-red-600 hover:bg-red-700" :class="{ 'opacity-25': form.processing }" :disabled="form.processing">
                                Lancer le processus de départ
                            </PrimaryButton>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </AuthenticatedLayout>
</template>
