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

const props = defineProps({
    permission: Object,
});

const form = useForm({
    name: props.permission.name,
});

const submit = () => {
    form.put(route('permissions.update', props.permission.id));
};
</script>

<template>
    <Head title="Modifier la Permission" />

    <AuthenticatedLayout>
        <template #header>
            <h2 class="text-xl font-semibold leading-tight text-gray-800 dark:text-gray-200">
                Modifier la Permission
            </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-6">
                    <form @submit.prevent="submit" class="space-y-6 max-w-xl">
                        <div>
                            <InputLabel for="name" value="Nom de la Permission (Tâche)" />
                            <TextInput 
                                id="name" 
                                type="text" 
                                class="mt-1 block w-full" 
                                v-model="form.name" 
                                required 
                                autofocus 
                            />
                            <InputError class="mt-2" :message="form.errors.name" />
                        </div>

                        <div class="flex items-center gap-4">
                            <PrimaryButton :disabled="form.processing">Enregistrer</PrimaryButton>
                            <Link :href="route('permissions.index')" class="text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 underline">Annuler</Link>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </AuthenticatedLayout>
</template>
