<?php
$currentPath = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
$isActive = fn (string $needle) => str_contains($currentPath, $needle) ? 'active' : '';
$flash = $_SESSION['flash'] ?? null;
unset($_SESSION['flash']);
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin &middot; <?= htmlspecialchars(APP_NAME) ?></title>
<meta name="robots" content="noindex, nofollow">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="<?= APP_URL ?>/assets/css/admin.css">
</head>
<body>
<div class="admin-shell">

  <aside class="admin-sidebar">
    <div class="admin-brand"><span class="dot"></span> Admin Fakultas</div>
    <nav class="admin-nav">
      <a href="<?= APP_URL ?>/admin" class="<?= trim($currentPath, '/') === 'admin' ? 'active' : '' ?>">Dashboard</a>

      <div class="group-label">Konten</div>
      <a href="<?= APP_URL ?>/admin/menu" class="<?= $isActive('admin/menu') ?>">Menu Navbar</a>
      <a href="<?= APP_URL ?>/admin/halaman" class="<?= $isActive('admin/halaman') ?>">Halaman Statis</a>
      <a href="<?= APP_URL ?>/admin/berita" class="<?= $isActive('admin/berita') || $isActive('admin/kategori-berita') ? 'active' : '' ?>">Berita</a>
      <a href="<?= APP_URL ?>/admin/agenda" class="<?= $isActive('admin/agenda') ?>">Agenda</a>
      <a href="<?= APP_URL ?>/admin/galeri-foto" class="<?= $isActive('admin/galeri-foto') ?>">Galeri Foto</a>
      <a href="<?= APP_URL ?>/admin/galeri-video" class="<?= $isActive('admin/galeri-video') ?>">Galeri Video</a>
      <a href="<?= APP_URL ?>/admin/fasilitas" class="<?= $isActive('admin/fasilitas') ?>">Fasilitas</a>

      <div class="group-label">Tampilan</div>
      <a href="<?= APP_URL ?>/admin/widget" class="<?= $isActive('admin/widget') ?>">Widget Sidebar</a>
      <a href="<?= APP_URL ?>/admin/footer" class="<?= $isActive('admin/footer') ?>">Footer</a>
      <a href="<?= APP_URL ?>/admin/identitas" class="<?= $isActive('admin/identitas') ?>">Identitas Kampus</a>
    </nav>
  </aside>

  <div class="admin-main">
    <header class="admin-topbar">
      <h1><?= htmlspecialchars($pageTitle ?? 'Dashboard') ?></h1>
      <div class="admin-user">
        <span><?= htmlspecialchars($admin['nama'] ?? '') ?></span>
        <a href="<?= APP_URL ?>/admin/logout">Keluar</a>
      </div>
    </header>

    <div class="admin-content">
      <?php if ($flash): ?>
        <div class="alert alert-<?= $flash['type'] === 'success' ? 'success' : 'error' ?>"><?= htmlspecialchars($flash['message']) ?></div>
      <?php endif; ?>
