<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'
import { Head, Link, useForm } from '@inertiajs/vue3'

const form = useForm({
    nom: '', raison_sociale: '', siret: '', adresse: '', code_postal: '', ville: '',
    telephone: '', email: '', contact_commercial: '', email_commercial: '',
    telephone_commercial: '', site_web: '', notes: '', active: true,
})

function submit() { form.post(route('fournisseurs.store')) }
</script>

<template>
    <Head title="Nouveau fournisseur" />
    <AuthenticatedLayout>
        <template #header>
            <div class="flex items-center gap-3">
                <Link :href="route('fournisseurs.index')" class="text-gray-400 hover:text-gray-600">
                    <svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" /></svg>
                </Link>
                <h1 class="text-xl font-semibold text-gray-900">Nouveau fournisseur</h1>
            </div>
        </template>

        <form @submit.prevent="submit" class="max-w-3xl space-y-6">
            <div class="rounded-xl bg-white p-6 shadow-sm border border-gray-100">
                <h2 class="mb-4 text-sm font-semibold uppercase tracking-wide text-gray-500">Informations</h2>
                <div class="grid gap-4 sm:grid-cols-2">
                    <div class="sm:col-span-2">
                        <label class="block text-sm font-medium text-gray-700">Nom <span class="text-red-500">*</span></label>
                        <input v-model="form.nom" type="text" required class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" />
                        <p v-if="form.errors.nom" class="mt-1 text-xs text-red-600">{{ form.errors.nom }}</p>
                    </div>
                    <div><label class="block text-sm font-medium text-gray-700">Raison sociale</label><input v-model="form.raison_sociale" type="text" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                    <div><label class="block text-sm font-medium text-gray-700">SIRET</label><input v-model="form.siret" type="text" maxlength="14" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                    <div class="sm:col-span-2"><label class="block text-sm font-medium text-gray-700">Adresse</label><textarea v-model="form.adresse" rows="2" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                    <div><label class="block text-sm font-medium text-gray-700">Code postal</label><input v-model="form.code_postal" type="text" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                    <div><label class="block text-sm font-medium text-gray-700">Ville</label><input v-model="form.ville" type="text" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                    <div><label class="block text-sm font-medium text-gray-700">Téléphone</label><input v-model="form.telephone" type="text" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                    <div><label class="block text-sm font-medium text-gray-700">Email</label><input v-model="form.email" type="email" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                    <div><label class="block text-sm font-medium text-gray-700">Site web</label><input v-model="form.site_web" type="url" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                    <div><label class="block text-sm font-medium text-gray-700">Contact commercial</label><input v-model="form.contact_commercial" type="text" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                    <div><label class="block text-sm font-medium text-gray-700">Email commercial</label><input v-model="form.email_commercial" type="email" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                    <div><label class="block text-sm font-medium text-gray-700">Tél. commercial</label><input v-model="form.telephone_commercial" type="text" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                    <div class="sm:col-span-2"><label class="block text-sm font-medium text-gray-700">Notes</label><textarea v-model="form.notes" rows="3" class="mt-1 block w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none" /></div>
                </div>
            </div>
            <div class="flex justify-end gap-3">
                <Link :href="route('fournisseurs.index')" class="rounded-lg border border-gray-300 px-5 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 transition-colors">Annuler</Link>
                <button type="submit" :disabled="form.processing" class="rounded-lg bg-blue-600 px-5 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50 transition-colors">{{ form.processing ? 'Création...' : 'Créer' }}</button>
            </div>
        </form>
    </AuthenticatedLayout>
</template>
