<?php
/**
 * Admin Sidebar
 * Patel E-Mitra & Aadhaar Seva Kendra CMS
 */

$current_page = basename($_SERVER['PHP_SELF']);
$current_dir = basename(dirname($_SERVER['PHP_SELF']));
?>

<aside id="sidebar" class="sidebar w-64 bg-gradient-to-b from-blue-900 to-purple-900 text-white flex-shrink-0 collapsed lg:collapsed-none">
    <div class="p-6">
        <!-- Logo -->
        <div class="flex items-center gap-3 mb-8">
            <div class="w-10 h-10 bg-white rounded-lg flex items-center justify-center">
                <i class="fa-solid fa-building-columns text-blue-900 text-xl"></i>
            </div>
            <div>
                <h2 class="font-bold text-sm">Patel E-Mitra</h2>
                <p class="text-xs text-blue-200">Admin Panel</p>
            </div>
        </div>
        
        <!-- Navigation Menu -->
        <nav class="space-y-1">
            <!-- Dashboard -->
            <a href="<?php echo SITE_URL; ?>/admin/index.php" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition <?php echo $current_page == 'index.php' ? 'bg-white bg-opacity-20' : 'hover:bg-white hover:bg-opacity-10'; ?>">
                <i class="fa-solid fa-gauge-high w-5"></i>
                <span>Dashboard</span>
            </a>
            
            <!-- Services -->
            <a href="<?php echo SITE_URL; ?>/admin/services/" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition <?php echo $current_dir == 'services' ? 'bg-white bg-opacity-20' : 'hover:bg-white hover:bg-opacity-10'; ?>">
                <i class="fa-solid fa-list-check w-5"></i>
                <span>Services</span>
            </a>
            
            <!-- Gallery -->
            <a href="<?php echo SITE_URL; ?>/admin/gallery/" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition <?php echo $current_dir == 'gallery' ? 'bg-white bg-opacity-20' : 'hover:bg-white hover:bg-opacity-10'; ?>">
                <i class="fa-solid fa-images w-5"></i>
                <span>Gallery</span>
            </a>
            
            <!-- Appointments -->
            <a href="<?php echo SITE_URL; ?>/admin/appointments/" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition <?php echo $current_dir == 'appointments' ? 'bg-white bg-opacity-20' : 'hover:bg-white hover:bg-opacity-10'; ?>">
                <i class="fa-solid fa-calendar-check w-5"></i>
                <span>Appointments</span>
                <?php
                $db = getDB();
                $stmt = $db->query("SELECT COUNT(*) as count FROM appointments WHERE status = 'pending'");
                $pending = $stmt->fetch()['count'];
                if ($pending > 0):
                ?>
                    <span class="ml-auto bg-red-500 text-white text-xs rounded-full px-2 py-1"><?php echo $pending; ?></span>
                <?php endif; ?>
            </a>
            
            <!-- Enquiries -->
            <a href="<?php echo SITE_URL; ?>/admin/enquiries/" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition <?php echo $current_dir == 'enquiries' ? 'bg-white bg-opacity-20' : 'hover:bg-white hover:bg-opacity-10'; ?>">
                <i class="fa-solid fa-envelope w-5"></i>
                <span>Enquiries</span>
                <?php
                $stmt = $db->query("SELECT COUNT(*) as count FROM enquiries WHERE status = 'new'");
                $new = $stmt->fetch()['count'];
                if ($new > 0):
                ?>
                    <span class="ml-auto bg-red-500 text-white text-xs rounded-full px-2 py-1"><?php echo $new; ?></span>
                <?php endif; ?>
            </a>
            
            <!-- Notices -->
            <a href="<?php echo SITE_URL; ?>/admin/notices/" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition <?php echo $current_dir == 'notices' ? 'bg-white bg-opacity-20' : 'hover:bg-white hover:bg-opacity-10'; ?>">
                <i class="fa-solid fa-bullhorn w-5"></i>
                <span>Notices</span>
            </a>
            
            <!-- Downloads -->
            <a href="<?php echo SITE_URL; ?>/admin/downloads/" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition <?php echo $current_dir == 'downloads' ? 'bg-white bg-opacity-20' : 'hover:bg-white hover:bg-opacity-10'; ?>">
                <i class="fa-solid fa-download w-5"></i>
                <span>Downloads</span>
            </a>
            
            <hr class="my-4 border-blue-700">
            
            <!-- Users (Admin only) -->
            <?php if ($_SESSION['role'] == 'admin'): ?>
            <a href="<?php echo SITE_URL; ?>/admin/users/" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition <?php echo $current_dir == 'users' ? 'bg-white bg-opacity-20' : 'hover:bg-white hover:bg-opacity-10'; ?>">
                <i class="fa-solid fa-users w-5"></i>
                <span>Users</span>
            </a>
            <?php endif; ?>
            
            <!-- Backup (Admin only) -->
            <?php if ($_SESSION['role'] == 'admin'): ?>
            <a href="<?php echo SITE_URL; ?>/admin/backup/" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition <?php echo $current_dir == 'backup' ? 'bg-white bg-opacity-20' : 'hover:bg-white hover:bg-opacity-10'; ?>">
                <i class="fa-solid fa-database w-5"></i>
                <span>Backup</span>
            </a>
            <?php endif; ?>
            
            <!-- Settings -->
            <a href="<?php echo SITE_URL; ?>/admin/settings.php" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition <?php echo $current_page == 'settings.php' ? 'bg-white bg-opacity-20' : 'hover:bg-white hover:bg-opacity-10'; ?>">
                <i class="fa-solid fa-gear w-5"></i>
                <span>Settings</span>
            </a>
            
            <hr class="my-4 border-blue-700">
            
            <!-- View Website -->
            <a href="<?php echo SITE_URL; ?>" target="_blank" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition hover:bg-white hover:bg-opacity-10">
                <i class="fa-solid fa-external-link-alt w-5"></i>
                <span>View Website</span>
            </a>
            
            <!-- Logout -->
            <a href="<?php echo SITE_URL; ?>/admin/logout.php" 
               class="flex items-center gap-3 px-4 py-3 rounded-lg transition hover:bg-red-600 hover:bg-opacity-50">
                <i class="fa-solid fa-right-from-bracket w-5"></i>
                <span>Logout</span>
            </a>
        </nav>
    </div>
</aside>
