@extends('admin.layout')

@section('title', 'Bannières & Promos')
@section('header', 'Bannières & Promos')

@section('content')
<nav class="mb-6">
    <a href="{{ route('admin.dashboard') }}" class="text-slate-500 hover:text-slate-900 text-sm">← Tableau de bord</a>
</nav>

<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
    <p class="text-slate-600 text-sm">Bandeaux promotionnels, pop-ups et annonces. Affichés sur le site selon les dates et la position.</p>
    <a href="{{ route('admin.banners.create') }}" class="inline-flex items-center gap-2 px-4 py-2 bg-primary-500 text-white rounded-xl font-medium hover:bg-primary-600 transition text-sm">
        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>
        Nouvelle bannière
    </a>
</div>

<div class="bg-white rounded-2xl border border-slate-200 overflow-hidden">
    @if($banners->isEmpty())
        <div class="p-12 text-center text-slate-500">
            <svg class="w-16 h-16 mx-auto mb-4 text-slate-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 4v16M17 4v16M3 8h4m10 0h4M3 12h18M3 16h4m10 0h4M4 20h16a1 1 0 001-1V5a1 1 0 00-1-1H4a1 1 0 00-1 1v14a1 1 0 001 1z"/></svg>
            <p class="font-medium">Aucune bannière</p>
            <p class="text-sm mt-1">Créez une bannière pour afficher des promos ou annonces sur le site.</p>
        </div>
    @else
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead class="bg-slate-50 border-b border-slate-200">
                    <tr>
                        <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Nom</th>
                        <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Type</th>
                        <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Position</th>
                        <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Période</th>
                        <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Statut</th>
                        <th class="text-right px-6 py-4 text-sm font-semibold text-slate-700">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    @foreach($banners as $b)
                        <tr class="hover:bg-slate-50/80 transition">
                            <td class="px-6 py-4 font-medium text-slate-900">{{ $b->name }}</td>
                            <td class="px-6 py-4">
                                <span class="text-sm">
                                    @if($b->type === 'bar') Bandeau
                                    @elseif($b->type === 'popup') Pop-up
                                    @else Alerte
                                    @endif
                                </span>
                            </td>
                            <td class="px-6 py-4 text-slate-600 text-sm">
                                @if($b->position === 'top') Haut
                                @elseif($b->position === 'bottom') Bas
                                @else Flottant
                                @endif
                            </td>
                            <td class="px-6 py-4 text-slate-500 text-sm">
                                @if($b->starts_at || $b->ends_at)
                                    {{ $b->starts_at?->format('d/m/Y') ?? '—' }} → {{ $b->ends_at?->format('d/m/Y') ?? '—' }}
                                @else
                                    Toujours
                                @endif
                            </td>
                            <td class="px-6 py-4">
                                @if($b->isCurrentlyActive())
                                    <span class="inline-flex px-2 py-0.5 rounded text-xs font-medium bg-emerald-100 text-emerald-800">Actif</span>
                                @else
                                    <span class="inline-flex px-2 py-0.5 rounded text-xs font-medium bg-slate-100 text-slate-600">Inactif</span>
                                @endif
                            </td>
                            <td class="px-6 py-4 text-right">
                                <a href="{{ route('admin.banners.edit', $b) }}" class="text-primary-600 hover:underline text-sm">Modifier</a>
                                <form method="POST" action="{{ route('admin.banners.destroy', $b) }}" class="inline ml-2" onsubmit="return confirm('Supprimer cette bannière ?')">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="text-red-600 hover:underline text-sm">Supprimer</button>
                                </form>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <div class="px-6 py-4 border-t border-slate-200">
            {{ $banners->links() }}
        </div>
    @endif
</div>
@endsection
