<?php
// admin/includes/sidebar.php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Get current page name
$current_page = basename($_SERVER['PHP_SELF']);

// Database connection for pending count
// Use __DIR__ to build an absolute path so includes work regardless of current working directory
require_once __DIR__ . '/../../config/db.php';
require_once __DIR__ . '/../../includes/rental-functions.php';
if (isset($conn)) {
    updateRentalStatuses($conn);
}

// Get pending verification count
$pending_count = 0;
$result = mysqli_query($conn, "SELECT COUNT(*) as count FROM user_id_proofs WHERE verification_status = 'pending'");
if ($result) {
    $row = mysqli_fetch_assoc($result);
    $pending_count = $row['count'];
}
?>
<div class="sidebar">
    <div class="sidebar-header">
        <h4>Admin Panel</h4>
        <p><?php echo $_SESSION['admin_user'] ?? 'Admin'; ?></p>
    </div>
    
    <div class="menu">
        <!-- DASHBOARD -->
        <a href="dashboard.php" class="menu-item <?php echo $current_page == 'dashboard.php' ? 'active' : ''; ?>">
            <i class="fas fa-home"></i> Dashboard
        </a>
        
        <!-- PRODUCTS -->
        <a href="products.php" class="menu-item <?php echo $current_page == 'products.php' ? 'active' : ''; ?>">
            <i class="fas fa-box"></i> View Products
        </a>
        
        <!-- ADD PRODUCT -->
        <a href="add-product.php" class="menu-item <?php echo $current_page == 'add-product.php' ? 'active' : ''; ?>">
            <i class="fas fa-plus"></i> Add Product
        </a>
        
        <!-- ORDERS -->
        <a href="orders.php" class="menu-item <?php echo $current_page == 'orders.php' ? 'active' : ''; ?>">
            <i class="fas fa-shopping-cart"></i> Orders
        </a>
        
        <!-- USERS -->
        <a href="manage-users.php" class="menu-item <?php echo $current_page == 'manage-users.php' ? 'active' : ''; ?>">
            <i class="fas fa-users"></i> Users
        </a>
        
        <!-- ✅✅✅ VERIFY USERS BUTTON - ALWAYS VISIBLE ✅✅✅ -->
        <a href="verify-users.php" class="menu-item <?php echo $current_page == 'verify-users.php' ? 'active' : ''; ?>">
            <i class="fas fa-id-card"></i> Verify Users
            <?php if($pending_count > 0): ?>
                <span class="badge"><?php echo $pending_count; ?></span>
            <?php endif; ?>
        </a>
        
        <!-- SETTINGS -->
        <a href="settings.php" class="menu-item <?php echo $current_page == 'settings.php' ? 'active' : ''; ?>">
            <i class="fas fa-cog"></i> Settings
        </a>
        
        <!-- LOGOUT -->
        <a href="../logout.php" class="menu-item logout">
            <i class="fas fa-sign-out-alt"></i> Logout
        </a>
    </div>
</div>

<style>
/* SIMPLE CSS - NO BREAKING CHANGES */
.sidebar {
    width: 220px;
    background: #2c3e50;
    min-height: 100vh;
    color: white;
    position: fixed;
    left: 0;
    top: 0;
}

.sidebar-header {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid #34495e;
}

.menu-item {
    display: block;
    color: white;
    padding: 12px 20px;
    text-decoration: none;
    border-left: 3px solid transparent;
    margin: 5px 0;
    transition: all 0.3s;
}

.menu-item:hover {
    background: #34495e;
    border-left-color: #3498db;
}

.menu-item.active {
    background: #34495e;
    border-left-color: #ff6b35;
    font-weight: bold;
}

.menu-item i {
    width: 20px;
    margin-right: 10px;
}

.badge {
    background: #ff6b35;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    float: right;
}

.logout {
    color: #e74c3c;
    margin-top: 20px;
    border-top: 1px solid #34495e;
    padding-top: 15px;
}
</style>