<?php
// admin_header.php - Admin Panel Header
// File location: /bidwheels.net/admin/includes/admin_header.php

// Start session and check admin login FIRST - before ANY output
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

require_once __DIR__ . '/../../config.php';

// Check if user is logged in and is admin
if (!isset($_SESSION['user_id']) || !isset($_SESSION['user_role']) || $_SESSION['user_role'] != 'admin') {
    header('Location: ' . SITE_URL . '/admin/login.php');
    exit();
}
?>
<!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 SITE_NAME; ?></title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: 'Inter', sans-serif;
            background: #0f0f0f;
            color: #ffffff;
        }
        .admin-wrapper {
            display: flex;
        }
        .admin-sidebar {
            width: 280px;
            background: #1a1a1a;
            min-height: 100vh;
            position: fixed;
            left: 0;
            top: 0;
            border-right: 1px solid #2a2a2a;
        }
        .admin-sidebar .logo {
            padding: 25px;
            text-align: center;
            border-bottom: 1px solid #2a2a2a;
        }
        .admin-sidebar .logo img {
            max-width: 50px;
            margin-bottom: 10px;
        }
        .admin-sidebar .logo h3 {
            font-size: 18px;
            color: #FF8C3E;
        }
        .admin-sidebar nav ul {
            list-style: none;
            padding: 20px 0;
        }
        .admin-sidebar nav ul li a {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 12px 25px;
            color: #aaa;
            text-decoration: none;
            transition: all 0.3s;
            font-size: 14px;
        }
        .admin-sidebar nav ul li a:hover,
        .admin-sidebar nav ul li.active a {
            background: #FF8C3E;
            color: #0a0a0a;
        }
        .admin-sidebar nav ul li a i {
            width: 20px;
        }
        .admin-content {
            margin-left: 280px;
            width: calc(100% - 280px);
            min-height: 100vh;
        }
        .admin-header {
            background: #1a1a1a;
            padding: 15px 25px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 1px solid #2a2a2a;
            position: sticky;
            top: 0;
            z-index: 100;
        }
        .admin-header h2 {
            font-size: 18px;
            font-weight: 500;
        }
        .admin-user {
            display: flex;
            align-items: center;
            gap: 20px;
        }
        .admin-user span {
            color: #ccc;
            font-size: 14px;
        }
        .admin-user a {
            color: #FF8C3E;
            text-decoration: none;
            font-size: 14px;
        }
        .admin-user a:hover {
            text-decoration: underline;
        }
        .admin-main {
            padding: 25px;
        }
        @media (max-width: 768px) {
            .admin-sidebar {
                width: 70px;
            }
            .admin-sidebar .logo h3,
            .admin-sidebar nav ul li a span {
                display: none;
            }
            .admin-content {
                margin-left: 70px;
                width: calc(100% - 70px);
            }
        }
    </style>
</head>
<body>
<div class="admin-wrapper">
    <div class="admin-sidebar">
        <div class="logo">
            <img src="<?php echo SITE_URL . SITE_LOGO; ?>" alt="Logo">
            <h3><?php echo SITE_NAME; ?></h3>
        </div>
        <nav>
            <ul>
                <li><a href="index.php"><i class="fas fa-tachometer-alt"></i> <span>Dashboard</span></a></li>
                <li><a href="products.php"><i class="fas fa-car"></i> <span>Products</span></a></li>
                <li><a href="add_product.php"><i class="fas fa-plus-circle"></i> <span>Add Product</span></a></li>
                <li><a href="reserved_products.php"><i class="fas fa-ban"></i> <span>Reserved</span></a></li>
                <li><a href="categories.php"><i class="fas fa-tags"></i> <span>Categories</span></a></li>
                <li><a href="bids.php"><i class="fas fa-gavel"></i> <span>Bids</span></a></li>
                <li><a href="comments.php"><i class="fas fa-comments"></i> <span>Comments</span></a></li>
                <li><a href="users.php"><i class="fas fa-users"></i> <span>Users</span></a></li>
                <li><a href="view_payments.php"><i class="fas fa-credit-card"></i> <span>Payments</span></a></li>
                <li><a href="payment_methods.php"><i class="fas fa-wallet"></i> <span>Payment Methods</span></a></li>
                <li><a href="blog_posts.php"><i class="fas fa-blog"></i> <span>Blog Posts</span></a></li>
                <li><a href="add_blog_post.php"><i class="fas fa-plus-circle"></i> <span>Add Blog Post</span></a></li>
                <li><a href="auto_bid_script.php"><i class="fas fa-magic"></i> <span>Auto Bid Script</span></a></li>
                <li><a href="reports.php"><i class="fas fa-chart-line"></i> <span>Reports</span></a></li>
                <li><a href="../user/logout.php"><i class="fas fa-sign-out-alt"></i> <span>Logout</span></a></li>
            </ul>
        </nav>
    </div>
    <div class="admin-content">
        <div class="admin-header">
            <h2>Welcome, <?php echo htmlspecialchars($_SESSION['user_name'] ?? 'Administrator'); ?></h2>
            <div class="admin-user">
                <span><i class="fas fa-user-shield"></i> Administrator</span>
                <a href="../user/logout.php"><i class="fas fa-sign-out-alt"></i> Logout</a>
            </div>
        </div>
        <div class="admin-main">