@extends('layouts.admin')

@section('title', 'Galerie / Realisations')

@php
    $breadcrumbs = [['label' => 'Realisations / Galerie']];
    $bulkFormId = 'bulk-gallery-form';
@endphp

@section('content')

    <div class="mb-5 flex flex-wrap items-center justify-between gap-3">
        <div class="flex flex-col gap-1">
            <h1 class="text-xl font-bold text-brand-ink">Realisations / Galerie</h1>
            <p class="text-sm text-brand-muted">{{ count($items) }} realisation(s) active(s) ou en brouillon.</p>
        </div>
        <a href="{{ route('admin.gallery.archives') }}" class="btn btn-secondary btn-sm"><x-icon name="archive" class="h-4 w-4" /> Voir les archives</a>
    </div>

    <form id="{{ $bulkFormId }}" method="POST" action="{{ route('admin.gallery.bulk') }}" class="hidden">@csrf</form>

    <div class="admin-card overflow-hidden" data-bulk-scope>
        <x-admin.list-toolbar search-placeholder="Rechercher une realisation..." add-label="Ajouter une realisation" :add-href="route('admin.gallery.create')" />

        @if (count($items) > 0)
            <div class="grid grid-cols-1 gap-4 p-4 sm:grid-cols-2 lg:grid-cols-3">
                @foreach ($items as $item)
                    <div class="lift-on-hover flex flex-col overflow-hidden rounded-xl border border-brand-border">
                        <div class="relative flex aspect-[4/3] items-center justify-center overflow-hidden bg-brand-surface text-brand-muted">
                            <input type="checkbox" data-row-select form="{{ $bulkFormId }}" name="ids[]" value="{{ $item['id'] }}" class="absolute left-2 top-2 z-10 h-4 w-4 rounded border-brand-border" aria-label="Selectionner {{ $item['title'] }}">
                            @if ($item['image'])
                                <img src="{{ $item['image'] }}" alt="" class="h-full w-full object-cover">
                            @else
                                <x-icon name="image-off" class="h-8 w-8" />
                            @endif
                            <span class="absolute right-2 top-2"><x-admin.status-badge :status="$item['status']" /></span>
                        </div>
                        <div class="flex flex-1 flex-col gap-2 p-3">
                            @if (!empty($item['category']))
                                <span class="w-fit rounded-full bg-brand-primary/10 px-2 py-0.5 text-[0.6875rem] font-semibold uppercase text-brand-primary">{{ $item['category'] }}</span>
                            @endif
                            <p class="text-sm font-semibold text-brand-ink">{{ $item['title'] }}</p>
                            <p class="text-xs text-brand-muted">Ordre {{ $item['sort_order'] }} - {{ $item['updated_at_demo'] }}</p>
                            <div class="mt-auto flex flex-wrap gap-1.5 pt-2">
                                <a href="{{ route('admin.gallery.edit', $item) }}" class="btn btn-secondary btn-sm flex-1">Modifier</a>
                                <form method="POST" action="{{ route('admin.gallery.toggle', $item) }}">@csrf @method('PATCH')<button type="submit" class="btn btn-ghost btn-sm" title="Publier/Depublier"><x-icon name="eye" class="h-4 w-4" /></button></form>
                                <form method="POST" action="{{ route('admin.gallery.archive', $item) }}">@csrf<button type="submit" data-confirm-action="archive" data-confirm-label="{{ $item['title'] }}" class="btn btn-ghost btn-sm" title="Archiver"><x-icon name="archive" class="h-4 w-4" /></button></form>
                            </div>
                        </div>
                    </div>
                @endforeach
            </div>
            <x-admin.pagination :current-page="1" :total-pages="1" :total-items="count($items)" />
        @else
            <x-admin.empty-state icon="image" title="Aucune realisation pour le moment" description="Ajoutez une realisation pour qu'elle apparaisse dans la galerie publique." action-label="Ajouter une realisation" :action-href="route('admin.gallery.create')" />
        @endif
    </div>

    <x-admin.bulk-actions-bar :actions="['toggle-status' => 'Publier', 'archive' => 'Archiver']" :form-id="$bulkFormId" />

@endsection
