<x-app-layout>
    <x-ui.page-header title="Modifier : {{ $form->title }}" />
    <x-alert />

    <div class="card p-6 max-w-4xl">
        <form method="POST" action="{{ route('admin.forms.update', $form) }}">
            @csrf @method('PUT')
            <div class="grid grid-cols-1 gap-5 mb-6">
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-1">Titre *</label>
                    <input type="text" name="title" value="{{ old('title', $form->title) }}" class="input-modern" required>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-1">Description</label>
                    <textarea name="description" rows="3" class="input-modern">{{ old('description', $form->description) }}</textarea>
                </div>
                <label class="inline-flex items-center gap-2">
                    <input type="checkbox" name="is_active" value="1" class="rounded border-slate-300 text-transtev-600" @checked(old('is_active', $form->is_active))>
                    <span class="text-sm font-medium text-slate-700">Formulaire actif (décocher pour verrouiller en lecture seule chez les filiales)</span>
                </label>
            </div>

            <h3 class="font-semibold text-slate-800 mb-4">Champs du formulaire</h3>
            <div class="flex items-start gap-2 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 mb-4 text-sm text-amber-800">
                <svg class="w-5 h-5 shrink-0 mt-0.5" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/></svg>
                <span>Modifier le libellé, le type ou les options d'un champ <strong>conserve</strong> les réponses déjà saisies par les filiales. En revanche, <strong>supprimer un champ efface définitivement</strong> les réponses associées.</span>
            </div>
            @include('partials.form-builder', ['fieldTypes' => $fieldTypes, 'initialFields' => $initialFields])

            <div class="flex gap-3 mt-8">
                <button type="submit" class="btn-primary">Enregistrer</button>
                <a href="{{ route('admin.forms.index') }}" class="btn-secondary">Annuler</a>
            </div>
        </form>
    </div>
</x-app-layout>
