<?php
/**
 * Sidebar Navigation Menu
 * نظام إدارة الجامعة
 */

if (!defined('SITE_URL')) {
    die('Direct access not allowed');
}
?>

<ul class="sidebar-menu">

    <?php if ($currentUser): ?>
        <div class="sidebar-header d-flex align-items-center justify-content-center py-3">
            <div class="d-flex align-items-center justify-content-center w-100 px-3">
                <a href="<?= SITE_URL ?>/index.php" class="btn btn-primary w-100 d-flex align-items-center justify-content-center shadow-sm py-2" style="border-radius: 10px; font-weight: bold; gap: 10px; transition: all 0.3s;">
                    <i class="fas fa-home" style="font-size: 1.2rem;"></i>
                    <span>الرئيسية</span>
                </a>
            </div>
        </div>

        <?php if (hasPermission('view_users') || hasPermission('view_roles') || hasPermission('view_company_data')): ?>
            <li class="menu-item has-submenu">
                <a href="#companyManagementSubmenu" class="menu-link collapsed" data-bs-toggle="collapse" role="button"
                   aria-expanded="false" aria-controls="companyManagementSubmenu">
                    <i class="fas fa-university menu-icon"></i> <span class="menu-text">إدارة الجامعة</span>
                    <i class="fas fa-chevron-down submenu-icon"></i>
                </a>
                <ul class="submenu collapse" id="companyManagementSubmenu">
                    <?php if (hasPermission('view_company_data')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/company/index.php" class="submenu-link">
                                <span class="menu-text">بيانات الجامعة</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    
                    <?php if (hasPermission('view_users')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/users/index.php" class="submenu-link">
                                <span class="menu-text">إدارة المستخدمين</span>
                            </a>
                        </li>
                    <?php endif; ?>

                    <?php if (hasPermission('view_roles')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/roles/index.php" class="submenu-link">
                                <span class="menu-text">الأدوار والصلاحيات</span>
                            </a>
                        </li>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/users/active_users.php" class="submenu-link">
                                <span class="menu-text">عرض أنشطة الدخول</span>
                            </a>
                        </li>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/users/log_file.php" class="submenu-link">
                                <span class="menu-text">سجل العمليات (Logs)</span>
                            </a>
                        </li>
                    <?php endif; ?>
                </ul>
            </li>
        <?php endif; ?>

        <?php if (hasPermission('view_expenses') || hasPermission('view_cashbox')): ?>
            <li class="menu-item has-submenu">
                <a href="#accountsSubmenu" class="menu-link collapsed" data-bs-toggle="collapse" role="button"
                   aria-expanded="false" aria-controls="accountsSubmenu">
                    <i class="fas fa-file-invoice-dollar menu-icon"></i> <span class="menu-text">المالية والحسابات</span>
                    <i class="fas fa-chevron-down submenu-icon"></i>
                </a>
                <ul class="submenu collapse" id="accountsSubmenu">
                    <?php if (hasPermission('view_expenses')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/expenses/index.php" class="submenu-link">
                                <span class="menu-text">سجل المصروفات</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (hasPermission('view_cashbox')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/cashbox/index.php" class="submenu-link">
                                <span class="menu-text">📊 الصندوق الرئيسي</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (hasPermission('view_expenses')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/expenses/financial_dashboard.php" class="submenu-link">
                                <span class="menu-text">التقارير المالية</span>
                            </a>
                        </li>
                    <?php endif; ?>
                </ul>
            </li>
        <?php endif; ?>

        <?php if (hasPermission('view_students')): ?>
            <li class="menu-item has-submenu">
                <a href="#studentsSubmenu" class="menu-link collapsed" data-bs-toggle="collapse" role="button"
                   aria-expanded="false" aria-controls="studentsSubmenu">
                    <i class="fas fa-user-graduate menu-icon"></i> <span class="menu-text">الطلاب</span>
                    <i class="fas fa-chevron-down submenu-icon"></i>
                </a>
                <ul class="submenu collapse" id="studentsSubmenu">
                    <?php if (hasPermission('view_students')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/student/index.php" class="submenu-link">
                                <span class="menu-text">عرض الطلاب</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (hasPermission('add_student')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/student/add_student.php" class="submenu-link">
                                <span class="menu-text">إضافة طالب جديد</span>
                            </a>
                        </li>
                    <?php endif; ?>
                </ul>
            </li>
        <?php endif; ?>

        <?php if (hasPermission('view_college')): ?>
            <li class="menu-item has-submenu">
                <a href="#collegeSubmenu" class="menu-link collapsed" data-bs-toggle="collapse" role="button"
                   aria-expanded="false" aria-controls="collegeSubmenu">
                    <i class="fas fa-landmark menu-icon"></i> <span class="menu-text">الكليات</span>
                    <i class="fas fa-chevron-down submenu-icon"></i>
                </a>
                <ul class="submenu collapse" id="collegeSubmenu">
                    <?php if (hasPermission('view_college')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/college/index.php" class="submenu-link">
                                <span class="menu-text">سجل الكليات</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (hasPermission('add_college')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/college/add_college.php" class="submenu-link">
                                <span class="menu-text">إضافة كلية جديدة</span>
                            </a>
                        </li>
                    <?php endif; ?>
                </ul>
            </li>
        <?php endif; ?>

        <?php if (hasPermission('view_schedule')): ?>
            <li class="menu-item has-submenu">
                <a href="#ScheduleSubmenu" class="menu-link collapsed" data-bs-toggle="collapse" role="button"
                   aria-expanded="false" aria-controls="ScheduleSubmenu">
                    <i class="fas fa-table menu-icon"></i> <span class="menu-text">الجداول</span>
                    <i class="fas fa-chevron-down submenu-icon"></i>
                </a>
                <ul class="submenu collapse" id="ScheduleSubmenu">
                    <?php if (hasPermission('view_schedule')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/schedule/index.php" class="submenu-link">
                                <span class="menu-text">سجل الجداول</span>
                            </a>
                        </li>
                    <?php endif; ?>
                     <?php if (hasPermission('add_schedule')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/schedule/add_schedule.php" class="submenu-link">
                                <span class="menu-text">تعديل جدول دراسي</span>
                            </a>
                        </li>
                    <?php endif; ?>
                </ul>
            </li>
        <?php endif; ?>

        <?php if (hasPermission('view_scores')): ?>
            <li class="menu-item has-submenu">
                <a href="#ScoresSubmenu" class="menu-link collapsed" data-bs-toggle="collapse" role="button"
                   aria-expanded="false" aria-controls="ScoresSubmenu">
                    <i class="fas fa-award menu-icon"></i> <span class="menu-text">الدرجات</span>
                    <i class="fas fa-chevron-down submenu-icon"></i>
                </a>
                <ul class="submenu collapse" id="ScoresSubmenu">
                    <?php if (hasPermission('view_scores')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/scores/index.php" class="submenu-link">
                                <span class="menu-text">سجل الدرجات</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (hasPermission('add_scores')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/scores/teacher_grades.php" class="submenu-link">
                                <span class="menu-text">إضافة درجات</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (hasPermission('manage_score_components')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/scores/score_components.php" class="submenu-link">
                                <span class="menu-text">إضافة مكونات الدرجات</span>
                            </a>
                        </li>
                    <?php endif; ?>
                </ul>
            </li>
        <?php endif; ?>

        <?php if (hasPermission('view_departments')): ?>
            <li class="menu-item has-submenu">
                <a href="#departmentsSubmenu" class="menu-link collapsed" data-bs-toggle="collapse" role="button"
                   aria-expanded="false" aria-controls="departmentsSubmenu">
                    <i class="fas fa-layer-group menu-icon"></i> <span class="menu-text">الأقسام</span>
                    <i class="fas fa-chevron-down submenu-icon"></i>
                </a>
                <ul class="submenu collapse" id="departmentsSubmenu">
                    <?php if (hasPermission('view_departments')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/department/index.php" class="submenu-link">
                                <span class="menu-text">سجل الأقسام</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (hasPermission('add_department')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/department/add_department.php" class="submenu-link">
                                <span class="menu-text">إضافة قسم جديد</span>
                            </a>
                        </li>
                    <?php endif; ?>
                     <?php if (hasPermission('show_lectures')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/department/show_lectures.php" class="submenu-link">
                                <span class="menu-text">عرض المحاضرات</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (hasPermission('add_lectures')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/department/add_lectures.php" class="submenu-link">
                                <span class="menu-text">إضافة محاضرة جديدة</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (hasPermission('show_halls')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/department/show_halls.php" class="submenu-link">
                                <span class="menu-text">عرض القاعات</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (hasPermission('add_halls')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/department/add_halls.php" class="submenu-link">
                                <span class="menu-text">إضافة قاعة</span>
                            </a>
                        </li>
                    <?php endif; ?>
                </ul>
            </li>
        <?php endif; ?>

         <?php if (hasPermission('view_faculty')): ?>
            <li class="menu-item has-submenu">
                <a href="#facultySubmenu" class="menu-link collapsed" data-bs-toggle="collapse" role="button"
                   aria-expanded="false" aria-controls="facultySubmenu">
                    <i class="fas fa-chalkboard-teacher menu-icon"></i> <span class="menu-text">الهيئة التدريسية</span>
                    <i class="fas fa-chevron-down submenu-icon"></i>
                </a>
                <ul class="submenu collapse" id="facultySubmenu">
                    <?php if (hasPermission('view_faculty')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/faculty/index.php" class="submenu-link">
                                <span class="menu-text">عرض الهيئة التدريسية</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (hasPermission('add_faculty')): ?>
                        <li class="submenu-item">
                            <a href="<?php echo SITE_URL; ?>/pages/faculty/add_faculty.php" class="submenu-link">
                                <span class="menu-text">إضافة تدريسيين</span>
                            </a>
                        </li>
                    <?php endif; ?>
                </ul>
            </li>
        <?php endif; ?>

        <?php if (hasPermission('view_employees')): ?>
            <li class="menu-item has-submenu">
                <a href="#employeesSubmenu" class="menu-link collapsed" data-bs-toggle="collapse" role="button"
                   aria-expanded="false" aria-controls="employeesSubmenu">
                    <i class="fas fa-user-tie menu-icon"></i>
                    <span class="menu-text">شؤون الموظفين</span>
                    <i class="fas fa-chevron-down submenu-icon"></i>
                </a>
                <ul class="submenu collapse" id="employeesSubmenu">
                    <li class="submenu-item">
                        <a href="<?php echo SITE_URL; ?>/pages/employees/index.php" class="submenu-link">
                            <span class="menu-text">عرض الموظفين</span>
                        </a>
                    </li>
                     <?php if (hasPermission('add_employee')): ?>
                    <li class="submenu-item">
                        <a href="<?php echo SITE_URL; ?>/pages/employees/add_employee.php" class="submenu-link">
                            <span class="menu-text">إضافة موظف جديد</span>
                        </a>
                    </li>
                      <?php endif; ?>
                </ul>
            </li>
        <?php endif; ?>

        <?php if (hasPermission('view_reports')): ?>
            <li class="menu-item">
                <a href="<?php echo SITE_URL; ?>/pages/reports/index.php" class="menu-link">
                    <i class="fas fa-chart-pie menu-icon"></i>
                    <span class="menu-text">مركز التقارير</span>
                </a>
            </li>
        <?php endif; ?>

        <?php if (hasPermission('system_settings')): ?>
            <li class="menu-item">
                <a href="<?php echo SITE_URL; ?>/pages/settings/index.php" class="menu-link">
                    <i class="fas fa-cogs menu-icon"></i>
                    <span class="menu-text">إعدادات النظام</span>
                </a>
            </li>
        <?php endif; ?>

    <?php endif; ?>

</ul>