<?php
require_once __DIR__ . '/../../functions.php';
ensure_role(['Admin', 'Manager']);
$user = current_user();
$flash = flash();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tumaini Cyber Admin</title>
    <link rel="stylesheet" href="<?= BASE_URL ?>assets/css/admin.css">
</head>
<body class="admin-layout">
<input type="hidden" id="csrf-token" value="<?= csrf_token() ?>">
<div class="sidebar">
    <div class="brand">
        <h2>Tumaini Cyber</h2>
        <small>Admin Panel</small>
    </div>
    <nav>
        <a href="index.php" class="<?= build_active_class('index.php') ?>">Overview</a>
        <a href="profile.php" class="<?= build_active_class('profile.php') ?>">Profile</a>
        <a href="users.php" class="<?= build_active_class('users.php') ?>">Users</a>
        <a href="settings.php" class="<?= build_active_class('settings.php') ?>">CMS Settings</a>
        <a href="shop.php" class="<?= build_active_class('shop.php') ?>">Shop</a>
        <a href="portfolio.php" class="<?= build_active_class('portfolio.php') ?>">Portfolio</a>
        <a href="settings.php#services-section" class="<?= (basename($_SERVER['PHP_SELF']) === 'settings.php' || basename($_SERVER['PHP_SELF']) === 'services.php') ? 'active' : '' ?>">Services</a>
        <a href="blog.php" class="<?= build_active_class('blog.php') ?>">Blog</a>
        <a href="quotes.php" class="<?= build_active_class('quotes.php') ?>">Quote Requests</a>
        <a href="messages.php" class="<?= build_active_class('messages.php') ?>">Messages</a>
        <a href="<?= BASE_URL ?>update.php" class="<?= build_active_class('update.php') ?>">Update Website</a>
        <a href="<?= BASE_URL ?>databaseupdate.php" class="<?= build_active_class('databaseupdate.php') ?>">Update Database</a>
    </nav>
</div>
<div class="main-shell">
    <header class="topbar">
        <div class="search-bar">
            <input type="search" placeholder="Search records..." onchange="window.location='#'">
        </div>
        <div class="topbar-actions">
            <div class="profile-pill">
                <?php if (!empty($user['profile_picture'])): ?>
                    <img src="<?= BASE_URL . UPLOAD_URL . '/' . clean($user['profile_picture']) ?>" alt="Avatar" class="profile-avatar">
                <?php endif; ?>
                <div>
                    <span><?= clean($user['name']) ?></span>
                    <small><?= clean($user['role']) ?></small>
                </div>
            </div>
            <a class="btn btn-danger" href="<?= BASE_URL ?>logout.php">Logout</a>
        </div>
    </header>
    <main>
        <?php if ($flash): ?>
            <div class="alert alert-<?= $flash['type'] ?>"><?= clean($flash['message']) ?></div>
        <?php endif; ?>
