<x-app-layout>
    <x-ui.page-header title="Assigner : {{ $form->title }}" description="Sélectionner les filiales et envoyer une notification" />
    <x-alert />

    <div class="card p-6 max-w-2xl">
        <form method="POST" action="{{ route('admin.forms.assign.store', $form) }}" class="space-y-6">
            @csrf
            <div>
                <label class="block text-sm font-medium text-slate-700 mb-3">Filiales *</label>
                <div class="space-y-2 max-h-64 overflow-y-auto p-4 rounded-xl bg-slate-50 border border-slate-100">
                    @foreach($filiales as $filiale)
                        <label class="flex items-center gap-3 p-2 rounded-lg hover:bg-white cursor-pointer transition">
                            <input type="checkbox" name="filiale_ids[]" value="{{ $filiale->id }}" class="rounded border-slate-300 text-transtev-600 focus:ring-transtev-500"
                                @checked(in_array($filiale->id, old('filiale_ids', $assignedIds)))>
                            <span class="font-medium text-slate-700">{{ $filiale->name }}</span>
                            <span class="text-xs text-slate-400">{{ $filiale->code }}</span>
                        </label>
                    @endforeach
                </div>
            </div>
            <div>
                <label class="block text-sm font-medium text-slate-700 mb-1">Date limite (optionnel)</label>
                <input type="date" name="due_date" value="{{ old('due_date') }}" class="input-modern max-w-xs">
            </div>
            <div class="flex gap-3">
                <button type="submit" class="btn-primary">Assigner et notifier</button>
                <a href="{{ route('admin.forms.show', $form) }}" class="btn-secondary">Retour</a>
            </div>
        </form>
    </div>
</x-app-layout>
