<?php
$currentPage = basename($_SERVER['PHP_SELF']);

$menuGroups = [
    'Main' => [
        ['file' => 'dashboard.php', 'label' => 'Dashboard', 'icon' => '⌂'],
        ['file' => 'products.php', 'label' => 'Products', 'icon' => '◈'],
        ['file' => 'categories.php', 'label' => 'Categories', 'icon' => '◇'],
        ['file' => 'orders.php', 'label' => 'Orders', 'icon' => '▣'],
        ['file' => 'customers.php', 'label' => 'Customers', 'icon' => '◎'],
    ],
    'Marketing' => [
        ['file' => 'abandoned-carts.php', 'label' => 'Abandoned Carts', 'icon' => '◌'],
        ['file' => 'newsletter-subscribers.php', 'label' => 'Newsletter', 'icon' => '✉'],
        ['file' => 'coupons.php', 'label' => 'Coupons', 'icon' => '%'],
        ['file' => 'reviews.php', 'label' => 'Reviews', 'icon' => '★'],
        ['file' => 'loyalty.php', 'label' => 'Loyalty', 'icon' => '◆'],
    ],
    'Operations' => [
        ['file' => 'payments.php', 'label' => 'Payments', 'icon' => '£'],
        ['file' => 'shipping.php', 'label' => 'Shipping', 'icon' => '⇄'],
        ['file' => 'faqs.php', 'label' => 'FAQs', 'icon' => '?'],
        ['file' => 'reports.php', 'label' => 'Reports', 'icon' => '▤'],
        ['file' => 'backups.php', 'label' => 'Backups', 'icon' => '↺'],
    ],
    'System' => [
        ['file' => 'settings.php', 'label' => 'Settings', 'icon' => '⚙'],
        ['file' => 'security.php', 'label' => 'Security', 'icon' => '◉'],
        ['file' => 'activity-logs.php', 'label' => 'Activity Logs', 'icon' => '☷'],
        ['file' => 'email-templates.php', 'label' => 'Email Templates', 'icon' => '✎'],
        ['file' => 'email-logs.php', 'label' => 'Email Logs', 'icon' => '☰'],
    ],
];
?>

<button type="button" class="admin-mobile-menu-btn" id="adminMobileMenuBtn" aria-label="Open admin menu">
    <span></span>
    <span></span>
    <span></span>
</button>

<div class="admin-sidebar-overlay" id="adminSidebarOverlay"></div>

<aside class="admin-sidebar lue-admin-sidebar" id="adminSidebar">
    <div class="admin-sidebar-brand">
        <div class="admin-sidebar-logo">
            <?= e(strtoupper(substr(APP_NAME, 0, 1))); ?>
        </div>

        <div>
            <h2><?= e(APP_NAME); ?></h2>
            <p>Admin Control Panel</p>
        </div>

        <button type="button" class="admin-sidebar-close" id="adminSidebarClose" aria-label="Close admin menu">×</button>
    </div>

    <nav class="admin-sidebar-nav">
        <?php foreach ($menuGroups as $groupTitle => $items): ?>
            <div class="admin-menu-group">
                <span class="admin-menu-title"><?= e($groupTitle); ?></span>

                <?php foreach ($items as $item): ?>
                    <a
                        class="admin-menu-link <?= $currentPage === $item['file'] ? 'active' : ''; ?>"
                        href="<?= e(ADMIN_URL); ?>/<?= e($item['file']); ?>"
                    >
                        <span class="admin-menu-icon"><?= e($item['icon']); ?></span>
                        <span><?= e($item['label']); ?></span>
                    </a>
                <?php endforeach; ?>
            </div>
        <?php endforeach; ?>
    </nav>

    <div class="admin-sidebar-footer">
        <a href="<?= e(BASE_URL); ?>/public/index.php" target="_blank" class="admin-menu-link admin-view-site">
            <span class="admin-menu-icon">↗</span>
            <span>View Website</span>
        </a>

        <a href="<?= e(ADMIN_URL); ?>/logout.php" class="admin-menu-link admin-logout-link">
            <span class="admin-menu-icon">⏻</span>
            <span>Logout</span>
        </a>
    </div>
</aside>

