
<!DOCTYPE html>

<html class="light" lang="fr">
    <head>
        <meta charset="utf-8"/>
        <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
        <title>Admin Event List</title>
        <!-- Google Fonts -->
        <link href="https://fonts.googleapis.com" rel="preconnect"/>
        <link crossorigin="" href="https://fonts.gstatic.com" rel="preconnect"/>
        <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700;900&amp;display=swap" rel="stylesheet"/>
        <!-- Material Symbols -->
        <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&amp;display=swap" rel="stylesheet"/>
        <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&amp;display=swap" rel="stylesheet"/>
        <!-- Tailwind CSS -->
        <script src="https://cdn.tailwindcss.com?plugins=forms,container-queries"></script>
        <!-- Tailwind Theme Config -->
        <script id="tailwind-config">
            tailwind.config = {
                darkMode: "class",
                theme: {
                    extend: {
                        colors: {
                            "primary": "#2b8cee",
                            "background-light": "#f6f7f8",
                            "background-dark": "#101922",
                        },
                        fontFamily: {
                            "display": ["Inter", "sans-serif"]
                        },
                        borderRadius: {"DEFAULT": "0.25rem", "lg": "0.5rem", "xl": "0.75rem", "full": "9999px"},
                    },
                },
            }
        </script>
    </head>
<body class="bg-background-light dark:bg-background-dark text-slate-900 dark:text-white font-display overflow-hidden">
    <div class="relative flex h-auto min-h-screen w-full flex-col overflow-x-hidden font-display text-[#111418]">
        <!-- Sidebar -->
        <header class="sticky top-0 z-50 flex items-center justify-between whitespace-nowrap border-b border-solid border-b-[#f0f2f4] bg-white px-4 py-3 lg:px-10">
            <div class="flex items-center gap-4 lg:gap-8">
                <div class="flex items-center gap-2 text-[#111418]">
                    <div class="size-8 text-primary">
                        <img src="<?= base_url('assets/img/MEN.jpg') ?>" alt="Mon logo" class="h-8 w-30 object-contain">
                    </div>
                    <h2 class="text-lg font-bold leading-tight tracking-[-0.015em] hidden sm:block">Evenement MEN</h2>
                   
                </div>
            </div>
            <div class="flex flex-1 justify-end gap-4 lg:gap-8 items-center">
                <div class="hidden md:flex items-center gap-6">
                    <a class="text-sm font-medium leading-normal hover:text-primary transition-colors" href="/">Acceuil</a>
                    <a class="text-primary transition-colors text-sm font-medium border-b-2 border-primary" href="totalEvenement">All Events</a>
                </div>
            </div>
             
        </header>
        <!-- Main Content -->
        <main class="flex-1 flex flex-col h-full overflow-hidden relative">
            <!-- Scrollable Content Area -->
            <div class="flex-1 overflow-y-auto p-4 md:p-8">
                <div class="max-w-7xl mx-auto flex flex-col gap-6">

                    <!-- Page Header -->
                    <div class="flex flex-col sm:flex-row sm:items-end justify-between gap-4">
                        <div class="flex flex-col gap-1">
                            <h2 class="text-slate-900 dark:text-white text-3xl font-bold tracking-tight">Listes des événements</h2>
                            <p class="text-slate-500 dark:text-slate-400 text-base">Suivez et gerez l'ensemble de nos événements, passés et à venir.</p>
                        </div>
                        <button onclick="openEventModal()" class="px-6 py-3 bg-blue-600 text-white rounded-xl hover:bg-blue-700">
                            <span class="material-symbols-outlined text-[20px]">add</span>
                            <span>Ajout Evenement</span>
                        </button>
                    </div>
                    <!-- Filters -->
                   <div class="bg-white dark:bg-slate-800 p-4 rounded-xl border border-slate-200 dark:border-slate-700 shadow-sm flex flex-col md:flex-row gap-4 items-end">
                        <div class="flex-1 w-full">
                            <label class="block text-xs font-medium text-slate-500 dark:text-slate-400 mb-1.5 uppercase tracking-wider">Search</label>
                            <div class="relative">
                                <span class="material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-slate-400">search</span>
                                <input class="w-full pl-10 pr-4 py-2.5 bg-slate-50 dark:bg-slate-700 border border-slate-200 dark:border-slate-600 rounded-lg text-slate-900 dark:text-white placeholder:text-slate-400 focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all text-sm" placeholder="Search by event name..." type="text"/>
                            </div>
                        </div>
                        <div class="w-full md:w-48">
                            <label class="block text-xs font-medium text-slate-500 dark:text-slate-400 mb-1.5 uppercase tracking-wider">Date</label>
                            <select class="w-full px-3 py-2.5 bg-slate-50 dark:bg-slate-700 border border-slate-200 dark:border-slate-600 rounded-lg text-slate-900 dark:text-white focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all text-sm appearance-none cursor-pointer">
                                <option value="">All Dates</option>
                                <option value="upcoming">Upcoming</option>
                                <option value="past">Past Month</option>
                                <option value="older">Older</option>
                            </select>
                        </div>
                    </div>
                    <!-- Table -->
                    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
                        <?php if (!empty($evenements)) : ?>
                            <?php foreach ($evenements as $event) : ?>
                               <!-- Card 1 -->
                                <div class="flex flex-col overflow-hidden rounded-xl bg-white shadow-sm hover:shadow-md transition-shadow border border-[#f0f2f4]">
                                    
                                    <div class="relative w-full aspect-video bg-gray-100">
                                        <div class="absolute inset-0 bg-cover bg-center" data-alt="People collaborating at a tech conference table" style="background-image: url('<?= base_url('uploads/evenements/' . $event['image']) ?>');">
                                        </div>
                                        <div class="absolute top-3 left-3 bg-white/90 backdrop-blur-sm px-2 py-1 rounded text-xs font-bold text-[#111418] shadow-sm uppercase tracking-wide">
                                            <?php
                                               $dateFin = new DateTime($event['date_fin']);
                                               $today   = new DateTime();

                                               if ($dateFin >= $today) {
                                                   $statut = "En cours";
                                                   $class  = "bg-green-600 text-white";
                                                } else {
                                                    $statut = "Terminé";
                                                    $class  = "bg-red-600 text-white";
                                                }
                                            ?>
                                            <div class="absolute top-3 left-3">
                                                <span class="<?= $class ?> px-3 py-1 rounded-full text-xs font-bold shadow-md uppercase tracking-wide whitespace-nowrap">
                                                     <?= $statut ?>
                                                </span>
                                            </div>                                                                                
                                        </div>
                                    </div>
                                    <div class="flex flex-col p-4 gap-3 flex-1">
                                        <div class="flex justify-between items-start">
                                            <p class="text-primary text-sm font-bold uppercase tracking-wide"><?= esc($event['libelle']) ?></p>
                                        </div>
                                        <h3 class="text-[#111418] text-lg font-bold leading-tight line-clamp-2 hover:text-primary cursor-pointer transition-colors">
                                            <?= esc($event['description']) ?>
                                        </h3>
                                        <div class="flex flex-col gap-1 mt-auto">
                                            <div class="flex items-center gap-2 text-[#617589]">
                                                <span class="material-symbols-outlined text-[18px]">location_on</span>
                                                <p class="text-sm font-normal truncate">San Francisco Convention Center</p>
                                            </div>
                                            <div class="flex items-center gap-2 text-[#617589]">
                                                <span class="material-symbols-outlined text-[18px]">event</span>
                                                <p class="text-sm font-normal"><?= esc($event['date_debut']) ?> → <?= esc($event['date_fin']) ?></p>
                                            </div>

                                        </div>
                                    
                                        <form action=<?= esc($event['libelle']) ?>>
                                            <button class="mt-2 w-full flex items-center justify-center rounded-lg h-9 bg-[#f0f2f4] text-[#111418] text-sm font-medium hover:bg-[#e5e7eb] transition-colors" type="submit">
                                            Voir Evenement</button>
                                        </form>
                                    </div>

                                </div>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </div>
                </div>
             </div>    
        </main>
    </div>

    <!-- MODAL AJOUT EVENEMENT -->
    <div id="eventModal"
        class="fixed inset-0 z-50 hidden items-center justify-center bg-black/60 backdrop-blur-sm">

        <div class="bg-white w-full max-w-2xl rounded-2xl shadow-xl p-6">

            <!-- HEADER -->
            <div class="flex justify-between items-center mb-6">
                <h2 class="text-xl font-semibold">Ajouter un événement</h2>
                <button onclick="closeEventModal()"
                    class="text-slate-500 hover:text-red-500 text-2xl">&times;</button>
            </div>

            <!-- FORM -->
            <form action="ajEvenement" method="post" enctype="multipart/form-data" class="space-y-6">

                <!-- Nom -->
                <div>
                    <label class="block text-sm font-medium mb-1">Nom de l’événement</label>
                    <input type="text" name="nom_evenement" placeholder="Ex : Arbre de Noël" class="w-full rounded-xl border px-4 py-3 focus:ring-2 focus:ring-blue-500">
                </div>

                <!-- Dates -->
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div>
                        <label class="block text-sm font-medium mb-1">Date de début</label>
                        <input type="date" name="date_debut" class="w-full rounded-xl border px-4 py-3">
                    </div>

                    <div>
                        <label class="block text-sm font-medium mb-1">Date de fin</label>
                        <input type="date" name="date_fin" class="w-full rounded-xl border px-4 py-3">
                    </div>
                </div>

                <!-- Description -->
                <div>
                    <label class="block text-sm font-medium mb-1">Description</label>
                    <textarea name="description" rows="4" placeholder="Décrivez l’événement..." class="w-full rounded-xl border px-4 py-3"></textarea>
                </div>

                <!-- Image -->
                <div>
                    <label class="block text-sm font-medium mb-2">Image</label>
                    <label class="flex flex-col items-center justify-center gap-2 p-6 border-2 border-dashed rounded-xl cursor-pointer hover:border-blue-500 transition">
                        <span class="material-symbols-outlined text-blue-600 text-3xl">upload</span>
                        <span class="text-sm text-slate-600 text-center"> Cliquez pour choisir une image<br>
                        <span class="text-xs">PNG, JPG — max 5MB</span>
                        </span>
                        <input type="file" name="image" accept="image/*" class="hidden">
                    </label>
                </div>

                <!-- FOOTER -->
                <div class="flex justify-end gap-4 pt-6 border-t"> 
                    <button type="button" onclick="closeEventModal()" class="px-6 py-3 rounded-xl border">Annuler</button>

                    <button type="submit" class="px-6 py-3 rounded-xl bg-blue-600 text-white font-medium hover:bg-blue-700"> Enregistrer</button>
                </div>

            </form>
        </div>
    </div>

    <script>
        function openEventModal() {
            document.getElementById('eventModal').classList.remove('hidden');
            document.getElementById('eventModal').classList.add('flex');
        }

        function closeEventModal() {
            document.getElementById('eventModal').classList.add('hidden');
            document.getElementById('eventModal').classList.remove('flex');
        }
    </script>


</body>
</html>
