<div>
    <div class="mb-6">
        <h1 class="text-2xl font-bold text-gray-900">Rientro Territorio</h1>
        <a href="{{ route('territori.show', $assegnazione->territorio) }}" class="text-sm text-indigo-600 hover:text-indigo-800">← Torna al territorio</a>
    </div>

    {{-- Assignment summary --}}
    <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 mb-6">
        <div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
            <div>
                <p class="text-xs font-medium text-gray-500 uppercase">Territorio</p>
                <p class="mt-1 text-lg font-bold text-gray-900">N° {{ $assegnazione->territorio->numero }}</p>
            </div>
            <div>
                <p class="text-xs font-medium text-gray-500 uppercase">Proclamatore</p>
                <p class="mt-1 text-sm text-gray-900">{{ $assegnazione->proclamatore->nome_completo }}</p>
            </div>
            <div>
                <p class="text-xs font-medium text-gray-500 uppercase">Assegnato il</p>
                <p class="mt-1 text-sm text-gray-900">{{ $assegnazione->assigned_at->format('d/m/Y') }}</p>
            </div>
        </div>
    </div>

    <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6 max-w-lg">
        <form wire:submit="save" class="space-y-4">
            <div>
                <label for="returned_at" class="block text-sm font-medium text-gray-700">Data Rientro *</label>
                <input wire:model.live="returned_at" type="date" id="returned_at"
                    min="{{ $assegnazione->assigned_at->format('Y-m-d') }}"
                    max="{{ now()->format('Y-m-d') }}"
                    class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm">
                @error('returned_at') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Campaign retroactive prompt --}}
            @if($showCampaignPrompt && $campagna)
            <div class="bg-amber-50 border border-amber-200 rounded-lg p-4">
                <p class="text-sm font-medium text-amber-800 mb-2">
                    ⚠️ Campagna Attiva: <strong>{{ $campagna->descrizione }}</strong>
                </p>
                <p class="text-xs text-amber-700 mb-3">
                    Questo territorio è stato assegnato durante la campagna "{{ $campagna->descrizione }}"
                    ({{ $campagna->start_date->format('d/m/Y') }} — {{ $campagna->end_date->format('d/m/Y') }}).
                    Vuoi conteggiarlo nella percentuale di percorrenza?
                </p>
                <div class="flex items-center gap-2">
                    <input wire:model="counted_in_campaign" type="checkbox" id="counted_in_campaign" class="rounded border-gray-300 text-amber-600 focus:ring-amber-500">
                    <label for="counted_in_campaign" class="text-sm text-amber-800">Sì, conteggia in campagna</label>
                </div>
            </div>
            @endif

            <div class="flex items-center gap-3 pt-4">
                <button type="submit" class="px-4 py-2 text-sm font-medium text-white bg-green-600 rounded-lg hover:bg-green-700 transition">Registra Rientro</button>
                <a href="{{ route('territori.show', $assegnazione->territorio) }}" class="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 transition">Annulla</a>
            </div>
        </form>
    </div>
</div>
