<?php
/**
 * Agentic Square - Premium Admin Sidebar Layout Engine
 */
$current_page = basename($_SERVER['PHP_SELF']);
$siteIdentity = function_exists('get_site_identity') ? get_site_identity() : ['business_name' => APP_NAME, 'logo_url' => ''];
$siteName = $siteIdentity['business_name'] ?? APP_NAME;
$siteLogoUrl = $siteIdentity['logo_url'] ?? '';
	
if (!isset($_SESSION['user_role']) || $_SESSION['user_role'] !== 'admin') {
    header('Location: ../login.php');
    exit;
}
?>

	<div class="lg:hidden fixed top-0 left-0 right-0 h-16 bg-nftDark/90 backdrop-blur-md border-b border-slate-800/60 flex items-center justify-between px-4 z-50">
	    <div class="flex items-center space-x-2">
	        <?php if (!empty($siteLogoUrl)): ?>
	            <div class="h-10 max-w-[170px] flex items-center">
	                <img src="<?php echo htmlspecialchars($siteLogoUrl, ENT_QUOTES, 'UTF-8'); ?>" alt="<?php echo htmlspecialchars($siteName, ENT_QUOTES, 'UTF-8'); ?> Logo" class="max-h-full max-w-full object-contain">
	            </div>
	        <?php else: ?>
	            <div class="w-8 h-8 bg-gradient-to-tr from-nftAccentCyan to-nftAccentPurple rounded-lg flex items-center justify-center font-bold text-sm text-white"><?php echo htmlspecialchars(strtoupper(substr($siteName, 0, 1)), ENT_QUOTES, 'UTF-8'); ?></div>
	            <span class="font-extrabold text-sm tracking-tight text-white max-w-[150px] truncate"><?php echo htmlspecialchars($siteName, ENT_QUOTES, 'UTF-8'); ?></span>
	        <?php endif; ?>
	    </div>
    <button id="mobile-sidebar-toggle" class="text-nftTextGray hover:text-white">
        <i class="fa-solid fa-bars-staggered text-xl"></i>
    </button>
</div>

<aside id="dashboard-sidebar" class="fixed top-0 bottom-0 left-0 w-64 bg-nftDark border-r border-slate-900/80 z-50 transform -translate-x-full lg:translate-x-0 transition-transform duration-300 ease-in-out pt-6 flex flex-col justify-between overflow-y-auto">
    
    <div class="px-4 space-y-7">
	        <div class="px-2 flex items-center space-x-3">
	            <?php if (!empty($siteLogoUrl)): ?>
	                <div class="h-12 max-w-[190px] flex items-center">
	                    <img src="<?php echo htmlspecialchars($siteLogoUrl, ENT_QUOTES, 'UTF-8'); ?>" alt="<?php echo htmlspecialchars($siteName, ENT_QUOTES, 'UTF-8'); ?> Logo" class="max-h-full max-w-full object-contain">
	                </div>
	            <?php else: ?>
	                <div class="w-10 h-10 bg-gradient-to-tr from-nftAccentCyan to-nftAccentPurple rounded-xl flex items-center justify-center font-bold text-xl text-white shadow-lg shadow-cyan-500/20"><?php echo htmlspecialchars(strtoupper(substr($siteName, 0, 1)), ENT_QUOTES, 'UTF-8'); ?></div>
	                <div class="flex flex-col min-w-0">
	                    <span class="text-xl font-extrabold text-transparent bg-clip-text bg-gradient-to-r from-white to-nftAccentCyan leading-none max-w-[160px] truncate"><?php echo htmlspecialchars($siteName, ENT_QUOTES, 'UTF-8'); ?></span>
	                    <span class="text-[9px] tracking-widest text-nftAccentPurple uppercase font-bold mt-1">Admin Panel</span>
	                </div>
	            <?php endif; ?>
	        </div>

        <nav class="space-y-6">
            <div class="space-y-1">
                <span class="text-[10px] font-bold text-slate-600 uppercase tracking-widest block mb-2 px-3">// Business Intelligence</span>
                <a href="admin-dashboard.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'admin-dashboard.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-gauge-high w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Dashboard</span>
                </a>
                <a href="reports.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'reports.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-chart-line w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Reports & Analytics</span>
                </a>
                <a href="all-orders.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'all-orders.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-bag-shopping w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Orders</span>
                </a>
            </div>

            <hr class="border-slate-900/60 my-2 mx-3">

            <div class="space-y-1">
                <span class="text-[10px] font-bold text-slate-600 uppercase tracking-widest block mb-2 px-3">// Digital Core Catalog</span>
                <a href="all-items.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'all-items.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-boxes-stacked w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>All Items</span>
                </a>
                <a href="add-item.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'add-item.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-circle-plus w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Add New Item</span>
                </a>
                <a href="category.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'category.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-layer-group w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Category</span>
                </a>
            </div>

            <hr class="border-slate-900/60 my-2 mx-3">

            <div class="space-y-1">
                <span class="text-[10px] font-bold text-slate-600 uppercase tracking-widest block mb-2 px-3">// Financial Ledgers</span>
                <a href="financial-dashboard.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'financial-dashboard.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-chart-pie w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Financial Dashboard</span>
                </a>
                <a href="transactions.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'transactions.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-receipt w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Transaction History</span>
                </a>
                <a href="withdrawals.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'withdrawals.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-wallet w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Withdrawal Request</span>
                </a>
            </div>

            <hr class="border-slate-900/60 my-2 mx-3">

            <div class="space-y-1">
                <span class="text-[10px] font-bold text-slate-600 uppercase tracking-widest block mb-2 px-3">// Relations & Trust</span>
                <a href="all-sellers.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'all-sellers.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-users-gear w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Sellers</span>
                </a>
                <a href="reviews.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'reviews.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-star w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Reviews</span>
                </a>
            </div>

            <hr class="border-slate-900/60 my-2 mx-3">

            <div class="space-y-1">
                <span class="text-[10px] font-bold text-slate-600 uppercase tracking-widest block mb-2 px-3">// Configuration</span>
                <a href="general-setting.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'general-setting.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-id-card w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Profile Setting</span>
                </a>
                <a href="settings.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'settings.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-user-gear w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Account Setting</span>
                </a>
                <a href="email-setting.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'email-setting.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-envelope-open-text w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Email Templates</span>
                </a>
                <a href="support-center.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'support-center.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-comments w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Support Center</span>
                </a>
                <a href="settings.php" class="flex items-center space-x-3 px-4 py-2.5 rounded-xl text-xs font-medium transition-all group <?php echo ($current_page == 'settings.php') ? 'bg-gradient-to-r from-nftAccentCyan/10 to-nftAccentPurple/10 border border-nftAccentCyan/20 text-nftAccentCyan font-bold' : 'text-nftTextGray hover:text-white hover:bg-slate-900/40' ?>">
                    <i class="fa-solid fa-sliders w-5 text-center group-hover:text-nftAccentCyan text-sm"></i>
                    <span>Settings Panel</span>
                </a>
            </div>
        </nav>
    </div>

    <div class="p-4 border-t border-slate-900/60 bg-nftDark shrink-0">
        <a href="../logout.php" class="flex items-center space-x-3 px-4 py-3 rounded-xl text-xs font-bold uppercase tracking-wider text-rose-400 hover:bg-rose-500/10 transition-all group">
            <i class="fa-solid fa-power-off w-5 text-center text-sm"></i>
            <span>Logout System</span>
        </a>
    </div>
</aside>

<div id="sidebar-overlay" class="fixed inset-0 bg-black/60 backdrop-blur-sm z-40 hidden lg:hidden"></div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const toggleBtn = document.getElementById('mobile-sidebar-toggle');
        const sidebar = document.getElementById('dashboard-sidebar');
        const overlay = document.getElementById('sidebar-overlay');
        function toggleSidebar() {
            sidebar.classList.toggle('-translate-x-full');
            overlay.classList.toggle('hidden');
        }
        if (toggleBtn) {
            toggleBtn.addEventListener('click', toggleSidebar);
            overlay.addEventListener('click', toggleSidebar);
        }
    });
</script>
