<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
    <title>Kesantrian Admin - Permits</title>
    <script src="https://cdn.tailwindcss.com?plugins=forms,container-queries"></script>
    <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&display=swap" rel="stylesheet"/>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Plus+Jakarta+Sans:wght@600;700&display=swap" rel="stylesheet"/>
    <script id="tailwind-config">
        tailwind.config = {
          darkMode: "class",
          theme: {
            extend: {
              colors: {
                  primary: "#006948",
                  "primary-container": "#00855d",
                  "on-primary": "#ffffff",
                  "surface": "#f8f9ff",
                  "on-surface": "#0b1c30",
                  "surface-container": "#e5eeff",
                  "surface-container-highest": "#d3e4fe",
                  "surface-container-lowest": "#ffffff",
                  "outline-variant": "#bccac0"
              }
            }
          }
        }
    </script>
</head>
<body class="bg-surface text-on-surface antialiased flex">

<!-- SideNavBar -->
<nav class="hidden md:flex flex-col fixed left-0 top-0 h-full py-8 bg-surface-container border-r border-outline-variant w-72 z-50">
    <div class="px-6 mb-8 flex items-center gap-4">
        <div>
            <h1 class="text-2xl font-bold text-primary m-0">Admin Panel</h1>
            <p class="text-sm text-gray-600 m-0">Kesantrian Division</p>
        </div>
    </div>
    <div class="flex-1 overflow-y-auto">
        <ul class="space-y-2">
            <li>
                <a class="flex items-center gap-3 px-4 py-3 text-gray-700 hover:bg-surface-container-highest transition-all rounded-lg mx-2" href="/kesantrian">
                    <span class="material-symbols-outlined">dashboard</span>
                    <span>Dashboard</span>
                </a>
            </li>
            <li>
                <a class="flex items-center gap-3 px-4 py-3 bg-primary text-on-primary rounded-lg mx-2 transition-all opacity-80" href="/kesantrian/permits">
                    <span class="material-symbols-outlined">assignment_turned_in</span>
                    <span>Permits</span>
                </a>
            </li>
            <li>
                <a class="flex items-center gap-3 px-4 py-3 text-gray-700 hover:bg-surface-container-highest transition-all rounded-lg mx-2" href="/santri">
                    <span class="material-symbols-outlined">group</span>
                    <span>Student Data</span>
                </a>
            </li>
            <li>
                <a class="flex items-center gap-3 px-4 py-3 text-gray-700 hover:bg-surface-container-highest transition-all rounded-lg mx-2" href="#">
                    <span class="material-symbols-outlined">manage_accounts</span>
                    <span>User Management</span>
                </a>
            </li>
            <li>
                <a class="flex items-center gap-3 px-4 py-3 text-gray-700 hover:bg-surface-container-highest transition-all rounded-lg mx-2" href="#">
                    <span class="material-symbols-outlined">assessment</span>
                    <span>Reports</span>
                </a>
            </li>
        </ul>
    </div>
    <div class="mt-auto px-6">
        <a class="flex items-center gap-3 px-4 py-3 text-gray-700 hover:bg-surface-container-highest transition-all rounded-lg mx-2" href="/auth/logout">
            <span class="material-symbols-outlined">logout</span>
            <span>Logout</span>
        </a>
    </div>
</nav>

<!-- Main Content Area -->
<main class="flex-1 md:ml-72 flex flex-col min-h-screen">
    <div class="pt-8 px-6 pb-24 w-full mx-auto">
        <div class="mb-8">
            <h2 class="text-3xl font-bold text-on-surface">Data Perizinan</h2>
            <p class="text-gray-600 mt-1">Daftar seluruh riwayat perizinan santri.</p>
        </div>

        <div class="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
            <div class="overflow-x-auto">
                <table class="w-full text-left border-collapse">
                    <thead>
                        <tr class="bg-gray-50 border-b border-gray-200">
                            <th class="p-4 font-semibold text-gray-700">Kode</th>
                            <th class="p-4 font-semibold text-gray-700">Santri</th>
                            <th class="p-4 font-semibold text-gray-700">Kategori</th>
                            <th class="p-4 font-semibold text-gray-700">Tanggal Izin</th>
                            <th class="p-4 font-semibold text-gray-700">Status Approval</th>
                            <th class="p-4 font-semibold text-gray-700">Status Gerbang</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        <?php if(empty($permits)): ?>
                            <tr>
                                <td colspan="6" class="p-4 text-center text-gray-500">Belum ada data perizinan.</td>
                            </tr>
                        <?php else: ?>
                            <?php foreach($permits as $p): ?>
                            <tr class="hover:bg-gray-50">
                                <td class="p-4 text-sm font-medium text-gray-900"><?= esc($p['kode_izin']) ?></td>
                                <td class="p-4">
                                    <div class="font-medium text-gray-900"><?= esc($p['nama_santri']) ?></div>
                                    <div class="text-xs text-gray-500">Kelas: <?= esc($p['kelas']) ?></div>
                                </td>
                                <td class="p-4 text-sm capitalize"><?= esc($p['kategori_izin']) ?></td>
                                <td class="p-4 text-sm text-gray-600">
                                    <?= date('d M Y', strtotime($p['tgl_mulai'])) ?> - <br>
                                    <?= date('d M Y', strtotime($p['tgl_kembali_rencana'])) ?>
                                </td>
                                <td class="p-4">
                                    <?php if ($p['status_approval'] == 'pending'): ?>
                                        <span class="px-2 py-1 bg-yellow-100 text-yellow-800 rounded text-xs font-semibold">Pending</span>
                                    <?php elseif ($p['status_approval'] == 'approved'): ?>
                                        <span class="px-2 py-1 bg-green-100 text-green-800 rounded text-xs font-semibold">Approved</span>
                                    <?php else: ?>
                                        <span class="px-2 py-1 bg-red-100 text-red-800 rounded text-xs font-semibold">Rejected</span>
                                    <?php endif; ?>
                                </td>
                                <td class="p-4 text-sm capitalize text-gray-600">
                                    <?= str_replace('_', ' ', $p['status_gerbang']) ?>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</main>
</body>
</html>
