<?php
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/functions.php';
requireLogin();  // every protected page must call this

// Determine current page for active navigation
$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>Admin Panel</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
    <link rel="stylesheet" href="../assets/css/style.css">
</head>
<body>

<!-- Top Navbar -->
<nav class="navbar navbar-dark bg-dark px-3">
    <button class="btn btn-outline-light d-md-none me-2" type="button" id="sidebarToggle">
        <i class="bi bi-list"></i>
    </button>
    <a class="navbar-brand" href="#">Reseller Admin</a>
    <div class="d-flex align-items-center text-white ms-auto">
        <span class="me-3 d-none d-md-inline"><?= htmlspecialchars($_SESSION['admin_name']) ?></span>
        <a href="../logout.php" class="btn btn-outline-light btn-sm">Logout</a>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <!-- Sidebar -->
        <nav id="sidebar" class="col-md-2 d-md-block sidebar">
            <div class="position-sticky pt-3">
                <ul class="nav flex-column">
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'dashboard' ? 'active' : '' ?>" href="dashboard.php">
                            <i class="bi bi-speedometer2"></i> Dashboard
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'categories' ? 'active' : '' ?>" href="categories.php">
                            <i class="bi bi-tags"></i> Categories
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'brands' ? 'active' : '' ?>" href="brands.php">
                            <i class="bi bi-bookmark"></i> Brands
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'products' ? 'active' : '' ?>" href="products.php">
                            <i class="bi bi-box-seam"></i> Products
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'orders' ? 'active' : '' ?>" href="orders.php">
                            <i class="bi bi-cart-check"></i> Orders
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'users' ? 'active' : '' ?>" href="users.php">
                            <i class="bi bi-people"></i> Resellers
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'subscriptions' ? 'active' : '' ?>" href="subscriptions.php">
                            <i class="bi bi-credit-card"></i> Subscriptions
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'wallet' ? 'active' : '' ?>" href="wallet.php">
                            <i class="bi bi-wallet2"></i> Wallet
                        </a>
                    </li>
                    <!-- New links -->
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'tutorials' ? 'active' : '' ?>" href="tutorials.php">
                            <i class="bi bi-play-btn"></i> Tutorials
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'banners' ? 'active' : '' ?>" href="banners.php">
                            <i class="bi bi-image"></i> Banners
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'registration_video' ? 'active' : '' ?>" href="/admin_panel/pages/registration_video.php">
                            <i class="bi bi-camera-video"></i> Registration Video
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $currentPage == 'settings' ? 'active' : '' ?>" href="settings.php">
                            <i class="bi bi-gear"></i> Settings
                        </a>
                    </li>
                </ul>
            </div>
        </nav>

        <!-- Main content -->
        <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4 py-4">