<?php
session_start();
require_once "../config/db.php";

if (!isset($_SESSION['admin_id'])) {
    header("Location: login.php");
    exit();
}

// Get pending verification count for sidebar
$pending_count = 0;
$result = mysqli_query($conn, 
    "SELECT COUNT(*) as count FROM user_id_proofs WHERE verification_status = 'pending'"
);
if ($result) {
    $data = mysqli_fetch_assoc($result);
    $pending_count = $data['count'];
}

$current_page = basename($_SERVER['PHP_SELF']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Panel - <?php echo $page_title ?? 'Dashboard'; ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --sidebar-width: 250px;
            --primary-color: #ff6b35;
            --sidebar-bg: #2c3e50;
        }
        
        .admin-sidebar {
            background: var(--sidebar-bg);
            min-height: 100vh;
            color: white;
            padding: 0;
            position: fixed;
            width: var(--sidebar-width);
            z-index: 1000;
            left: 0;
            top: 0;
            box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        }
        
        .admin-main {
            margin-left: var(--sidebar-width);
            padding: 20px;
            background: #f8f9fa;
            min-height: 100vh;
        }
        
        .sidebar-header {
            padding: 25px 20px;
            background: rgba(255,255,255,0.05);
            text-align: center;
            border-bottom: 1px solid rgba(255,255,255,0.1);
        }
        
        .nav-item {
            margin: 5px 10px;
        }
        
        .nav-link {
            color: rgba(255,255,255,0.9);
            padding: 12px 15px;
            border-radius: 8px;
            transition: all 0.3s;
        }
        
        .nav-link:hover, .nav-link.active {
            background: rgba(255,107,53,0.2);
            color: white;
        }
        
        .nav-link i {
            width: 20px;
            text-align: center;
            margin-right: 10px;
        }
        
        .verification-badge {
            background: #ff6b35;
            color: white;
            border-radius: 10px;
            padding: 2px 8px;
            font-size: 0.8rem;
            margin-left: auto;
        }
        
        @media (max-width: 768px) {
            .admin-sidebar {
                width: 70px;
            }
            .admin-main {
                margin-left: 70px;
            }
            .nav-link span:not(.verification-badge) {
                display: none;
            }
        }
    </style>
</head>
<body>
    <div class="admin-sidebar">
        <div class="sidebar-header">
            <i class="fas fa-user-shield fa-2x mb-2" style="color: #ff6b35;"></i>
            <h6 class="mb-0"><?php echo htmlspecialchars($_SESSION['admin_user']); ?></h6>
            <small class="text-muted">Administrator</small>
        </div>
        
        <nav class="nav flex-column mt-3">
            <div class="nav-item">
                <a class="nav-link <?php echo $current_page == 'dashboard.php' ? 'active' : ''; ?>" href="dashboard.php">
                    <i class="fas fa-tachometer-alt"></i>
                    <span>Dashboard</span>
                </a>
            </div>
            
            <div class="nav-item">
                <a class="nav-link <?php echo $current_page == 'add-product.php' ? 'active' : ''; ?>" href="add-product.php">
                    <i class="fas fa-plus-circle"></i>
                    <span>Add Product</span>
                </a>
            </div>
            
            <div class="nav-item">
                <a class="nav-link <?php echo $current_page == 'products.php' ? 'active' : ''; ?>" href="products.php">
                    <i class="fas fa-box"></i>
                    <span>View Products</span>
                </a>
            </div>
            
            <div class="nav-item">
                <a class="nav-link <?php echo $current_page == 'orders.php' ? 'active' : ''; ?>" href="orders.php">
                    <i class="fas fa-shopping-cart"></i>
                    <span>View Orders</span>
                </a>
            </div>
            
            <div class="nav-item">
                <a class="nav-link <?php echo $current_page == 'manage-users.php' ? 'active' : ''; ?>" href="manage-users.php">
                    <i class="fas fa-users"></i>
                    <span>Manage Users</span>
                </a>
            </div>
            
            <!-- Separate Verification Button -->
            <div class="nav-item">
                <a class="nav-link <?php echo $current_page == 'verify-users.php' ? 'active' : ''; ?>" href="verify-users.php">
                    <i class="fas fa-id-card"></i>
                    <span>Verify Users ID</span>
                    <?php if ($pending_count > 0): ?>
                        <span class="verification-badge"><?php echo $pending_count; ?></span>
                    <?php endif; ?>
                </a>
            </div>
            
            <div class="nav-item">
                <a class="nav-link <?php echo $current_page == 'settings.php' ? 'active' : ''; ?>" href="settings.php">
                    <i class="fas fa-cog"></i>
                    <span>Settings</span>
                </a>
            </div>
            
            <div class="nav-item">
                <a class="nav-link <?php echo $current_page == 'notifications.php' ? 'active' : ''; ?>" href="notifications.php">
                    <i class="fas fa-bell"></i>
                    <span>Notifications</span>
                </a>
            </div>
            
            <div class="nav-item mt-4">
                <a class="nav-link text-danger" href="../logout.php">
                    <i class="fas fa-sign-out-alt"></i>
                    <span>Logout</span>
                </a>
            </div>
        </nav>
    </div>
    
    <div class="admin-main">
        <!-- Page content will go here -->