<?php
$adminTitle = $adminTitle ?? 'UGFX Admin';
$bootstrapCss = ugfx_vendor_asset('assets/vendor/bootstrap/css/bootstrap.min.css', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css', '../');
$currentAdminPage = basename($_SERVER['PHP_SELF'] ?? 'dashboard.php');
$currentAdminUser = ugfx_admin_current_user();
$onlineAdmins = ugfx_admin_online_users();
$allAdminNav = [
    'dashboard.php' => 'Dashboard',
    'chat.php' => 'Chat',
    'news.php' => 'News',
    'events.php' => 'Events',
    'pages.php' => 'Pages',
    'friends.php' => 'Friends',
    'djs.php' => 'DJs / Team',
    'schedule.php' => 'Schedule',
    'requests.php' => 'Requests',
    'contact.php' => 'Contact',
    'applications.php' => 'Applications',
    'users.php' => 'Users & Roles',
];
$adminNav = [];
foreach ($allAdminNav as $file => $label) {
    $permission = match ($file) {
        'dashboard.php' => 'dashboard',
        'chat.php' => 'chat',
        'news.php' => 'news',
        'events.php' => 'events',
        'pages.php' => 'pages',
        'friends.php' => 'friends',
        'djs.php' => 'djs',
        'schedule.php' => 'schedule',
        'requests.php' => 'requests',
        'contact.php' => 'contact',
        'applications.php' => 'applications',
        'users.php' => 'users',
        default => 'dashboard',
    };
    if (ugfx_admin_can($permission)) $adminNav[$file] = $label;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($adminTitle) ?></title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800&family=Orbitron:wght@700;800&display=swap" rel="stylesheet">
<link href="<?= htmlspecialchars($bootstrapCss) ?>" rel="stylesheet">
<link rel="stylesheet" href="../assets/css/theme.css">
</head>
<body class="ugfx-admin-shell">
<div class="container-fluid">
<div class="row">
<aside class="col-lg-2 p-3 ugfx-admin-sidebar">
    <div class="ugfx-brand mb-4"><span class="ugfx-brand-mark">FX</span><span class="ugfx-brand-text">Admin</span></div><div class="ugfx-card p-3 mb-3"><div class="ugfx-micro-label">SIGNED IN</div><div class="fw-bold"><?= htmlspecialchars((string)($currentAdminUser['username'] ?? 'Admin')) ?></div><div class="d-flex gap-2 align-items-center mt-2 flex-wrap"><span class="ugfx-chip">Role: <?= htmlspecialchars(ucfirst((string)($currentAdminUser['role'] ?? 'admin'))) ?></span><?php if (!empty($currentAdminUser['temp_login'])): ?><span class="ugfx-chip">Temp local login</span><?php endif; ?><span class="ugfx-chip ugfx-chip-blue"><i class="bi bi-broadcast"></i> <?= count($onlineAdmins) ?> online</span></div></div>
    <nav class="d-grid gap-1">
        <?php foreach ($adminNav as $file => $label): ?>
            <a href="<?= htmlspecialchars($file) ?>" class="<?= $currentAdminPage === $file ? 'active' : '' ?>"><?= htmlspecialchars($label) ?></a>
        <?php endforeach; ?>
        <a href="logout.php">Logout</a>
    </nav>
</aside>
<section class="col-lg-10 p-4">
