<?php
$currentPage = basename($_SERVER['PHP_SELF'], '.php');
$isAdmin = isAdmin();
$basePath = $isAdmin ? '/admin' : '/student';
?>
<div class="sidebar" id="sidebar">
    <div class="sidebar-brand">
        <div class="brand-icon">📚</div>
        <span class="brand-name"><?= APP_NAME ?></span>
        <button class="sidebar-close" id="sidebarClose"><i class="fa fa-times"></i></button>
    </div>
    
    <?php if (!$isAdmin): ?>
    <!-- Exam Countdown in Sidebar -->
    <?php $examDate = getActiveExamCountdown(); if ($examDate): ?>
    <div class="sidebar-countdown">
        <div class="countdown-label">📅 <?= htmlspecialchars($examDate['exam_name']) ?></div>
        <div class="countdown-timer" id="sidebarCountdown" data-date="<?= $examDate['exam_date'] ?>">
            <span id="sc-days">--</span>d <span id="sc-hours">--</span>h <span id="sc-mins">--</span>m
        </div>
    </div>
    <?php endif; ?>
    <?php endif; ?>

    <nav class="sidebar-nav">
        <?php if ($isAdmin): ?>
        <!-- Admin Navigation -->
        <div class="nav-section-label">Admin Panel</div>
        <a href="<?= APP_URL ?>/admin/dashboard" class="nav-item <?= $currentPage === 'dashboard' ? 'active' : '' ?>">
            <i class="fa fa-gauge-high"></i><span>Dashboard</span>
        </a>
        <a href="<?= APP_URL ?>/admin/users" class="nav-item <?= $currentPage === 'users' ? 'active' : '' ?>">
            <i class="fa fa-users"></i><span>Students</span>
        </a>
        <a href="<?= APP_URL ?>/admin/subjects" class="nav-item <?= $currentPage === 'subjects' ? 'active' : '' ?>">
            <i class="fa fa-book"></i><span>Subjects</span>
        </a>
        <a href="<?= APP_URL ?>/admin/exam-dates" class="nav-item <?= $currentPage === 'exam-dates' ? 'active' : '' ?>">
            <i class="fa fa-calendar"></i><span>A/L Exam Dates</span>
        </a>
        <a href="<?= APP_URL ?>/admin/announcements" class="nav-item <?= $currentPage === 'announcements' ? 'active' : '' ?>">
            <i class="fa fa-bullhorn"></i><span>Announcements</span>
        </a>
        <a href="<?= APP_URL ?>/admin/analytics" class="nav-item <?= $currentPage === 'analytics' ? 'active' : '' ?>">
            <i class="fa fa-chart-line"></i><span>Analytics</span>
        </a>
        <?php else: ?>
        <!-- Student Navigation -->
        <div class="nav-section-label">Main</div>
        <a href="<?= APP_URL ?>/student/dashboard" class="nav-item <?= $currentPage === 'dashboard' ? 'active' : '' ?>">
            <i class="fa fa-gauge-high"></i><span>Dashboard</span>
        </a>
        <a href="<?= APP_URL ?>/student/study-log" class="nav-item <?= $currentPage === 'study-log' ? 'active' : '' ?>">
            <i class="fa fa-clock"></i><span>Study Log</span>
        </a>
        <a href="<?= APP_URL ?>/student/class-hours" class="nav-item <?= $currentPage === 'class-hours' ? 'active' : '' ?>">
            <i class="fa fa-chalkboard-teacher"></i><span>Class Hours</span>
        </a>
        <a href="<?= APP_URL ?>/student/marks" class="nav-item <?= $currentPage === 'marks' ? 'active' : '' ?>">
            <i class="fa fa-star"></i><span>Marks</span>
        </a>

        <div class="nav-section-label">Analysis</div>
        <a href="<?= APP_URL ?>/student/analytics" class="nav-item <?= $currentPage === 'analytics' ? 'active' : '' ?>">
            <i class="fa fa-chart-bar"></i><span>Analytics</span>
        </a>
        <a href="<?= APP_URL ?>/student/goals" class="nav-item <?= $currentPage === 'goals' ? 'active' : '' ?>">
            <i class="fa fa-bullseye"></i><span>Goals</span>
        </a>

        <div class="nav-section-label">More</div>
        <a href="<?= APP_URL ?>/student/profile" class="nav-item <?= $currentPage === 'profile' ? 'active' : '' ?>">
            <i class="fa fa-user"></i><span>Profile</span>
        </a>
        <?php endif; ?>
    </nav>

    <div class="sidebar-footer">
        <div class="user-info">
            <div class="user-avatar"><?= strtoupper(substr($_SESSION['user_name'], 0, 1)) ?></div>
            <div>
                <div class="user-name"><?= htmlspecialchars($_SESSION['user_name']) ?></div>
                <div class="user-role"><?= ucfirst($_SESSION['user_role']) ?></div>
            </div>
        </div>
        <a href="<?= APP_URL ?>/logout" class="btn-logout" title="Logout">
            <i class="fa fa-right-from-bracket"></i>
        </a>
    </div>
</div>
<div class="sidebar-overlay" id="sidebarOverlay"></div>
