<?php
/**
 * Tom's Java Jive - Admin Header
 * Requires AdminAuth::require() — redirects to login.php
 */

require_once __DIR__ . '/../../includes/auth.php';

AdminAuth::require();

$adminUser = AdminAuth::getUser();

$currentPage = basename($_SERVER['PHP_SELF'], '.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $pageTitle ?? 'Admin' ?> - Tom's Java Jive Admin</title>
    
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    <link rel="stylesheet" href="/admin/assets/admin.css">
    
    <?php if (isset($extraHead)) echo $extraHead; ?>
</head>
<body class="admin-body">
    <div class="admin-layout">
        <!-- Sidebar -->
        <aside class="admin-sidebar">
            <div class="sidebar-header">
                <a href="/admin/" class="admin-logo">
                    <img src="/assets/images/logo.png?v=<?= filemtime($_SERVER['DOCUMENT_ROOT'] . '/assets/images/logo.png') ?>" alt="Logo" class="logo-img" style="height: 50px;">
                    <span>Admin</span>
                </a>
            </div>
            
            <nav class="sidebar-nav">
                <a href="/admin/" class="nav-item <?= $currentPage === 'index' ? 'active' : '' ?>">
                    <i class="fas fa-chart-line"></i> Dashboard
                </a>
                
                <div class="nav-group">
                    <span class="nav-group-title">Sales</span>
                    <a href="/admin/orders.php" class="nav-item <?= $currentPage === 'orders' ? 'active' : '' ?>">
                        <i class="fas fa-shopping-cart"></i> Orders
                    </a>
                    <a href="/admin/pos.php" class="nav-item <?= $currentPage === 'pos' ? 'active' : '' ?>">
                        <i class="fas fa-cash-register"></i> POS
                    </a>
                    <a href="/admin/analytics.php" class="nav-item <?= $currentPage === 'analytics' ? 'active' : '' ?>">
                        <i class="fas fa-chart-bar"></i> Analytics
                    </a>
                </div>
                
                <div class="nav-group">
                    <span class="nav-group-title">Catalog</span>
                    <a href="/admin/products.php" class="nav-item <?= $currentPage === 'products' ? 'active' : '' ?>">
                        <i class="fas fa-box"></i> Products
                    </a>
                    <a href="/admin/categories.php" class="nav-item <?= $currentPage === 'categories' ? 'active' : '' ?>">
                        <i class="fas fa-tags"></i> Categories
                    </a>
                    <a href="/admin/product-types.php" class="nav-item <?= $currentPage === 'product-types' ? 'active' : '' ?>">
                        <i class="fas fa-layer-group"></i> Product Types
                    </a>
                    <a href="/admin/inventory.php" class="nav-item <?= $currentPage === 'inventory' ? 'active' : '' ?>">
                        <i class="fas fa-warehouse"></i> Inventory
                    </a>
                    <a href="/admin/import-export.php" class="nav-item <?= $currentPage === 'import-export' ? 'active' : '' ?>">
                        <i class="fas fa-file-csv"></i> Import / Export
                    </a>
                </div>
                
                <div class="nav-group">
                    <span class="nav-group-title">Customers</span>
                    <a href="/admin/customers.php" class="nav-item <?= $currentPage === 'customers' ? 'active' : '' ?>">
                        <i class="fas fa-users"></i> Customers
                    </a>
                    <a href="/admin/reviews.php" class="nav-item <?= $currentPage === 'reviews' ? 'active' : '' ?>">
                        <i class="fas fa-star"></i> Reviews
                    </a>
                </div>
                
                <div class="nav-group">
                    <span class="nav-group-title">Content</span>
                    <a href="/admin/splashes.php" class="nav-item <?= $currentPage === 'splashes' ? 'active' : '' ?>">
                        <i class="fas fa-th-large"></i> Splash Box
                    </a>
                    <a href="/admin/about-us.php" class="nav-item <?= $currentPage === 'about-us' ? 'active' : '' ?>">
                        <i class="fas fa-align-left"></i> About Us Text
                    </a>
                </div>

                <div class="nav-group">
                    <span class="nav-group-title">Marketing</span>
                    <a href="/admin/gift-cards.php" class="nav-item <?= $currentPage === 'gift-cards' ? 'active' : '' ?>">
                        <i class="fas fa-gift"></i> Gift Cards
                    </a>
                    <a href="/admin/coupons.php" class="nav-item <?= $currentPage === 'coupons' ? 'active' : '' ?>">
                        <i class="fas fa-ticket-alt"></i> Coupons
                    </a>
                    <a href="/admin/campaigns.php" class="nav-item <?= $currentPage === 'campaigns' ? 'active' : '' ?>">
                        <i class="fas fa-envelope"></i> Email Campaigns
                    </a>
                    <a href="/admin/email-log.php" class="nav-item <?= $currentPage === 'email-log' ? 'active' : '' ?>"><i class="fas fa-envelope-open-text"></i> Email Log</a>
                </div>
                
                <div class="nav-group">
                    <a href="/admin/settings.php" class="nav-item <?= $currentPage === 'settings' ? 'active' : '' ?>">
                        <i class="fas fa-cog"></i> Store Settings
                    </a>
                    <a href="/admin/integrations.php" class="nav-item <?= $currentPage === 'integrations' ? 'active' : '' ?>">
                        <i class="fas fa-plug"></i> Integrations
                    </a>
                    <a href="/admin/shipping.php" class="nav-item <?= $currentPage === 'shipping' ? 'active' : '' ?>">
                        <i class="fas fa-truck"></i> Shipping
                    </a>
                    <a href="/admin/payments.php" class="nav-item <?= $currentPage === 'payments' ? 'active' : '' ?>">
                        <i class="fas fa-credit-card"></i> Payments
                    </a>
                    <a href="/admin/users.php" class="nav-item <?= $currentPage === 'users' ? 'active' : '' ?>">
                        <i class="fas fa-user-shield"></i> Admin Users
                    </a>
                </div>
            </nav>
            
            <div class="sidebar-footer">
                <a href="/" target="_blank" class="nav-item">
                    <i class="fas fa-external-link-alt"></i> View Store
                </a>
            </div>
        </aside>
        
        <!-- Main Content -->
        <div class="admin-main">
            <header class="admin-header">
                <button class="sidebar-toggle" id="sidebarToggle">
                    <i class="fas fa-bars"></i>
                </button>
                
                <div class="header-search">
                    <i class="fas fa-search"></i>
                    <input type="text" placeholder="Search...">
                </div>
                
                <div class="header-actions">
                    <div class="admin-user">
                        <span><?= htmlspecialchars($adminUser['name']) ?></span>
                        <a href="/admin/logout.php" class="btn btn-sm">
                            <i class="fas fa-sign-out-alt"></i>
                        </a>
                    </div>
                </div>
            </header>
            
            <main class="admin-content">
                <?php if (hasFlash('success')): ?>
                <div style="background:rgba(16,185,129,.12);border:1px solid rgba(16,185,129,.35);color:#10b981;padding:13px 16px;border-radius:8px;margin-bottom:20px;font-size:14px;font-weight:500;display:flex;align-items:center;gap:10px">
                    <i class="fas fa-check-circle" style="font-size:16px"></i> <?= getFlash('success') ?>
                </div>
                <?php endif; ?>
                <?php if (hasFlash('error')): ?>
                <div style="background:rgba(220,38,38,.1);border:1px solid rgba(220,38,38,.3);color:#f87171;padding:13px 16px;border-radius:8px;margin-bottom:20px;font-size:14px;font-weight:500;display:flex;align-items:center;gap:10px">
                    <i class="fas fa-exclamation-circle" style="font-size:16px"></i> <?= getFlash('error') ?>
                </div>
                <?php endif; ?>
                <?php if (hasFlash('info')): ?>
                <div style="background:rgba(59,130,246,.1);border:1px solid rgba(59,130,246,.3);color:#60a5fa;padding:13px 16px;border-radius:8px;margin-bottom:20px;font-size:14px;font-weight:500;display:flex;align-items:center;gap:10px">
                    <i class="fas fa-info-circle" style="font-size:16px"></i> <?= getFlash('info') ?>
                </div>
                <?php endif; ?>
                <?php if (hasFlash('warning')): ?>
                <div style="background:rgba(245,158,11,.1);border:1px solid rgba(245,158,11,.3);color:#f59e0b;padding:13px 16px;border-radius:8px;margin-bottom:20px;font-size:14px;font-weight:500;display:flex;align-items:center;gap:10px">
                    <i class="fas fa-exclamation-triangle" style="font-size:16px"></i> <?= getFlash('warning') ?>
                </div>
                <?php endif; ?>
                <?php if (hasFlash("success")): ?><div style="background:rgba(16,185,129,.12);border:1px solid rgba(16,185,129,.35);color:#10b981;padding:13px 16px;border-radius:8px;margin-bottom:20px;font-size:14px;font-weight:500;display:flex;align-items:center;gap:8px"><i class="fas fa-check-circle"></i><?= getFlash("success") ?></div><?php endif; ?>
                <?php if (hasFlash("error")): ?><div style="background:rgba(220,38,38,.1);border:1px solid rgba(220,38,38,.3);color:#f87171;padding:13px 16px;border-radius:8px;margin-bottom:20px;font-size:14px;font-weight:500;display:flex;align-items:center;gap:8px"><i class="fas fa-exclamation-circle"></i><?= getFlash("error") ?></div><?php endif; ?>
                <?php if (hasFlash("info")): ?><div style="background:rgba(59,130,246,.1);border:1px solid rgba(59,130,246,.3);color:#60a5fa;padding:13px 16px;border-radius:8px;margin-bottom:20px;font-size:14px;font-weight:500;display:flex;align-items:center;gap:8px"><i class="fas fa-info-circle"></i><?= getFlash("info") ?></div><?php endif; ?>
