<?php
/**
 * Admin Sidebar Layout Header Template
 * Path: admin/layout-header.php
 */

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
    header('Location: login.php');
    exit;
}

require_once '../config.php';
require_once '../function.php';

$site_name = get_site_setting('site_name');
$site_logo = get_site_logo(true);
$current_page = basename($_SERVER['PHP_SELF']);

$nav_items = [
    ['file' => 'index.php',        'icon' => 'fa-gauge-high',         'label' => 'Dashboard'],
    ['file' => 'settings.php',     'icon' => 'fa-sliders',            'label' => 'General Settings'],
    ['file' => 'banner.php',       'icon' => 'fa-image',              'label' => 'Banner Manager'],
    ['file' => 'marquee.php',      'icon' => 'fa-align-left',         'label' => 'Marquee Text'],
    ['file' => 'products.php',     'icon' => 'fa-boxes-stacked',      'label' => 'Products'],
    ['file' => 'categories.php',   'icon' => 'fa-layer-group',        'label' => 'Cat & Com'],
    ['file' => 'faqs.php',         'icon' => 'fa-circle-question',    'label' => 'FAQs'],
    ['file' => 'reviews.php',      'icon' => 'fa-star',               'label' => 'Reviews'],
    ['file' => 'inquiries.php',    'icon' => 'fa-envelope-open-text', 'label' => 'Quote Requests'],
    ['file' => 'chatbot.php',      'icon' => 'fa-robot',              'label' => 'Chatbot Training'],
    ['file' => 'chat-history.php', 'icon' => 'fa-comments',           'label' => 'Chat History'],
    ['file' => 'blogs.php',        'icon' => 'fa-newspaper',          'label' => 'News & Blogs'],
    ['file' => 'projects.php',     'icon' => 'fa-briefcase',          'label' => 'Projects'],
];

function nav_class($file, $current) {
    if ($file === $current) {
        return 'bg-adminAccent text-slate-950 shadow-md shadow-adminAccent/10';
    }
    return 'text-slate-400 hover:bg-slate-800 hover:text-white';
}
?>
<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Panel - <?php echo htmlspecialchars($site_name); ?></title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        adminDarkBg: '#0f172a',
                        adminCardBg: '#1e293b',
                        adminAccent: '#0ea5e9'
                    }
                }
            }
        }
    </script>
    <style>
        .admin-sidebar::-webkit-scrollbar { width: 4px; }
        .admin-sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
    </style>
</head>
<body class="bg-adminDarkBg text-slate-100 font-sans min-h-screen flex flex-col md:flex-row">

    <!-- Mobile Top Bar -->
    <div class="md:hidden bg-adminCardBg border-b border-slate-800 p-4 flex justify-between items-center w-full sticky top-0 z-40">
        <div class="flex items-center space-x-3">
            <img class="w-8 h-8 rounded-full object-cover border border-adminAccent/30" src="<?php echo htmlspecialchars($site_logo); ?>" alt="Logo">
            <span class="font-bold text-sm text-adminAccent uppercase tracking-wide">Admin Panel</span>
        </div>
        <button id="mobile-sidebar-toggle" class="text-slate-400 hover:text-white focus:outline-none" aria-label="Toggle sidebar">
            <i class="fa-solid fa-bars text-xl" id="sidebar-icon"></i>
        </button>
    </div>

    <!-- Sidebar -->
    <aside id="admin-sidebar" class="admin-sidebar hidden md:flex flex-col w-full md:w-64 bg-slate-900 border-r border-slate-800/80 flex-shrink-0 z-30 transition-all duration-300 md:block max-h-screen md:sticky md:top-0 md:h-screen overflow-y-auto">

        <div class="hidden md:flex items-center space-x-3 p-6 pb-5 border-b border-slate-800/80">
            <img class="w-10 h-10 rounded-full object-cover border-2 border-adminAccent/30 shadow-md" src="<?php echo htmlspecialchars($site_logo); ?>" alt="Logo">
            <div class="overflow-hidden">
                <h2 class="font-black text-xs text-adminAccent uppercase tracking-wider truncate"><?php echo htmlspecialchars($site_name); ?></h2>
                <span class="text-[10px] text-slate-500 font-bold uppercase tracking-widest">Management Panel</span>
            </div>
        </div>

        <nav class="flex-1 p-4 space-y-1">
            <?php foreach ($nav_items as $item): ?>
                <a href="<?php echo $item['file']; ?>"
                   class="flex items-center px-4 py-2.5 rounded-xl transition-all text-sm font-semibold <?php echo nav_class($item['file'], $current_page); ?>">
                    <i class="fa-solid <?php echo $item['icon']; ?> w-6 text-base"></i>
                    <?php echo $item['label']; ?>
                </a>
            <?php endforeach; ?>
        </nav>

        <div class="p-4 border-t border-slate-800/80 space-y-2">
            <a href="change-password.php" class="flex items-center px-4 py-2.5 rounded-lg text-xs font-bold <?php echo $current_page === 'change-password.php' ? 'bg-adminAccent text-slate-950' : 'text-amber-400 hover:bg-amber-950/30 hover:text-amber-300'; ?> transition-all">
                <i class="fa-solid fa-key w-5 text-sm"></i> Change Password
            </a>
            <a href="../index.php" target="_blank" class="flex items-center px-4 py-2.5 rounded-lg text-xs font-bold text-slate-400 hover:bg-slate-800 hover:text-white transition-all">
                <i class="fa-solid fa-globe w-5 text-sm"></i> View Live Site
            </a>
            <a href="logout.php" class="flex items-center px-4 py-2.5 rounded-lg text-xs font-bold text-red-400 hover:bg-red-950/30 hover:text-red-300 transition-all">
                <i class="fa-solid fa-right-from-bracket w-5 text-sm"></i> Sign Out
            </a>
        </div>
    </aside>

    <script>
        const toggleBtn = document.getElementById('mobile-sidebar-toggle');
        const sidebar   = document.getElementById('admin-sidebar');
        const icon      = document.getElementById('sidebar-icon');
        if (toggleBtn) {
            toggleBtn.addEventListener('click', () => {
                sidebar.classList.toggle('hidden');
                icon.className = sidebar.classList.contains('hidden')
                    ? 'fa-solid fa-bars text-xl'
                    : 'fa-solid fa-xmark text-xl';
            });
        }
    </script>

    <div class="flex-1 flex flex-col min-w-0">
