<?php
// Sidebar Layout Template
// This file provides the sidebar navigation structure

function renderSidebar($current_page = '', $user_role = 'admin', $user_name = 'ব্যবহারকারী') {
    // Get site settings
    if (function_exists('get_all_settings') && isset($GLOBALS['pdo'])) {
        $settings = get_all_settings($GLOBALS['pdo']);
        $site_name = $settings['site_name'] ?? 'বিদ্যা নিকেতন';
        $logo_image = $settings['logo_image'] ?? null;
        // Get system name for branding
        $system_name = get_system_name($GLOBALS['pdo']);
        
        // Get pending bank transactions count for admin users
        $pending_transactions_count = 0;
        if ($user_role == 'admin' && isset($GLOBALS['pdo'])) {
            try {
                $stmt = $GLOBALS['pdo']->query("SELECT COUNT(*) as count FROM bank_transactions WHERE status = 'pending'");
                $result = $stmt->fetch();
                $pending_transactions_count = $result['count'];
            } catch (Exception $e) {
                $pending_transactions_count = 0;
            }
        }
    } else {
        $site_name = 'বিদ্যা নিকেতন';
        $logo_image = null;
        $system_name = 'স্কুল ম্যানেজমেন্ট সিস্টেম';
        $pending_transactions_count = 0;
    }

    $menu_items = getSidebarMenuItems($user_role, $pending_transactions_count);
    
    ob_start();
    ?>
    <!-- Hind Siliguri Font -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        /* Apply Hind Siliguri font to all elements */
        body, html {
            font-family: 'Hind Siliguri', sans-serif !important;
        }
        
        /* Ensure all text elements use Hind Siliguri */
        *, *::before, *::after {
            font-family: 'Hind Siliguri', sans-serif !important;
        }
        
        /* Override any other font declarations */
        h1, h2, h3, h4, h5, h6, p, span, div, a, button, input, textarea, select, label, table, th, td {
            font-family: 'Hind Siliguri', sans-serif !important;
        }
        
        /* Specific sidebar font styling */
        .sidebar, .sidebar * {
            font-family: 'Hind Siliguri', sans-serif !important;
        }
        
        .nav-text, .nav-section-title, .sidebar-title, .sidebar-subtitle, 
        .user-name, .user-role, .nav-dropdown-item {
            font-family: 'Hind Siliguri', sans-serif !important;
        }
        
        /* Font Awesome Icons - Restore Original Font */
        .fas, .far, .fab, .fa,
        .fas::before, .far::before, .fab::before, .fa::before,
        .fas::after, .far::after, .fab::after, .fa::after,
        i[class*="fa-"], i[class*="fa-"]::before, i[class*="fa-"]::after {
            font-family: 'Font Awesome 6 Free', 'Font Awesome 5 Free', 'FontAwesome' !important;
            font-weight: 900 !important;
        }
        
        .far, .far::before, .far::after {
            font-weight: 400 !important;
        }
        
        .fab, .fab::before, .fab::after {
            font-family: 'Font Awesome 6 Brands', 'Font Awesome 5 Brands', 'FontAwesome' !important;
        }
        
        /* Sidebar specific icon fixes */
        .sidebar .fas, .sidebar .far, .sidebar .fab, .sidebar .fa,
        .sidebar .fas::before, .sidebar .far::before, .sidebar .fab::before, .sidebar .fa::before,
        .nav-link i, .nav-dropdown-toggle i, .nav-dropdown-item i,
        .sidebar-toggle i, .mobile-toggle i {
            font-family: 'Font Awesome 6 Free', 'Font Awesome 5 Free', 'FontAwesome' !important;
            font-weight: 900 !important;
        }
        
        /* Dropdown chevron icon fix - positioned beside text */
        .nav-dropdown-toggle::after {
            font-family: 'Font Awesome 6 Free', 'Font Awesome 5 Free', 'FontAwesome' !important;
            font-weight: 900 !important;
            margin-left: 8px;
            display: inline-block;
        }
        
        /* Navigation icon specific fix */
        .nav-icon i, .nav-icon .fas, .nav-icon .far, .nav-icon .fab {
            font-family: 'Font Awesome 6 Free', 'Font Awesome 5 Free', 'FontAwesome' !important;
            font-weight: 900 !important;
        }
        
        /* Position nav-text and chevron correctly */
        .nav-dropdown-toggle {
            display: flex;
            align-items: center;
        }
        
        .nav-dropdown-toggle .nav-text {
            margin-right: 8px;
        }
    </style>
    
    <!-- Mobile Toggle Button -->
    <button class="mobile-toggle d-md-none" onclick="toggleMobileSidebar()">
        <i class="fas fa-bars"></i>
    </button>
    
    <!-- Mobile Overlay -->
    <div class="mobile-overlay" onclick="closeMobileSidebar()"></div>
    
    <!-- Sidebar -->
    <div class="sidebar" id="sidebar">
        <!-- Sidebar Header -->
        <div class="sidebar-header">
            <button class="sidebar-toggle" onclick="toggleSidebar()">
                <i class="fas fa-chevron-left"></i>
            </button>
            <div class="sidebar-logo">
                <?php
                    $logo_path = $logo_image;
                    if ($logo_image && !preg_match('/^https?:\/\//i', $logo_image)) {
                        $logo_path = __DIR__ . '/../' . ltrim($logo_image, '/');
                    }
                ?>
                <?php if ($logo_image && ($logo_path && file_exists($logo_path))): ?>
                    <img src="<?php echo htmlspecialchars('../' . $logo_image); ?>" alt="Logo" style="height: 40px; width: auto;">
                <?php else: ?>
                    <i class="fas fa-graduation-cap"></i>
                <?php endif; ?>
            </div>
            <h3 class="sidebar-title"><?php echo htmlspecialchars($site_name); ?></h3>
            <p class="sidebar-subtitle"><?php echo htmlspecialchars($system_name); ?></p>
        </div>
        
        <!-- User Profile -->
        <div class="sidebar-user">
            <div class="user-avatar">
                <i class="fas fa-user"></i>
            </div>
            <h4 class="user-name"><?php echo htmlspecialchars($user_name); ?></h4>
            <p class="user-role"><?php echo getRoleDisplayName($user_role); ?></p>
        </div>
        
        <!-- Navigation Menu -->
        <nav class="sidebar-nav">
            <?php foreach ($menu_items as $section): ?>
                <div class="nav-section">
                    <?php if (!empty($section['title'])): ?>
                        <div class="nav-section-title"><?php echo $section['title']; ?></div>
                    <?php endif; ?>
                    
                    <?php foreach ($section['items'] as $item): ?>
                        <div class="nav-item">
                            <?php if (isset($item['submenu'])): ?>
                                <!-- Dropdown Menu -->
                                <div class="nav-dropdown" data-dropdown="<?php echo $item['id']; ?>">
                                    <a href="#" class="nav-link nav-dropdown-toggle" onclick="toggleDropdown('<?php echo $item['id']; ?>')">
                                        <span class="nav-icon">
                                            <i class="<?php echo $item['icon']; ?>"></i>
                                        </span>
                                        <span class="nav-text"><?php echo $item['text']; ?></span>
                                        <?php if ($item['id'] === 'admin'): ?>
                                            <span class="nav-update-animation">&nbsp;আপডেট</span>
                                        <?php endif; ?>
                                        <?php if (isset($item['badge'])): ?>
                                            <span class="nav-badge"><?php echo $item['badge']; ?></span>
                                        <?php endif; ?>
                                    </a>
                                    <div class="nav-dropdown-menu">
                                        <?php foreach ($item['submenu'] as $subitem): ?>
                                            <?php if (isset($subitem['roles']) && !in_array($user_role, (array)$subitem['roles'])) continue; ?>
                                            <a href="<?php echo $subitem['url']; ?>" 
                                               class="nav-dropdown-item <?php echo isActivePage($subitem['url'], $current_page) ? 'active' : ''; ?>">
                                                <?php if (isset($subitem['icon'])): ?>
                                                    <i class="<?php echo $subitem['icon']; ?>" style="margin-right: 8px;"></i>
                                                <?php endif; ?>
                                                <?php echo $subitem['text']; ?>
                                                <?php if (isset($subitem['badge'])): ?>
                                                    <span class="badge bg-danger ms-2" style="font-size: 0.65em; padding: 2px 6px; border-radius: 10px;"><?php echo $subitem['badge']; ?></span>
                                                <?php endif; ?>
                                            </a>
                                        <?php endforeach; ?>
                                    </div>
                                </div>
                            <?php else: ?>
                                <!-- Regular Menu Item -->
                                <a href="<?php echo $item['url']; ?>" 
                                   class="nav-link <?php echo isActivePage($item['url'], $current_page) ? 'active' : ''; ?>">
                                    <span class="nav-icon">
                                        <i class="<?php echo $item['icon']; ?>"></i>
                                    </span>
                                    <span class="nav-text"><?php echo $item['text']; ?></span>
                                    <?php if (isset($item['badge'])): ?>
                                        <span class="nav-badge"><?php echo $item['badge']; ?></span>
                                    <?php endif; ?>
                                </a>
                            <?php endif; ?>
                        </div>
                    <?php endforeach; ?>
                </div>
            <?php endforeach; ?>
            
            <!-- Logout -->
            <div class="nav-section">
                <div class="nav-item">
                    <a href="logout.php" class="nav-link" onclick="return confirm('আপনি কি লগআউট করতে চান?')">
                        <span class="nav-icon">
                            <i class="fas fa-sign-out-alt"></i>
                        </span>
                        <span class="nav-text">লগআউট</span>
                    </a>
                </div>
            </div>
        </nav>
    </div>
    
    <style>
        .nav-update-animation {
            display: inline-block;
            color: #ff3333;
            font-weight: bold;
            animation: pulse-update 1.5s infinite;
            margin-left: 5px;
            font-size: 0.85em;
            text-transform: uppercase;
            text-shadow: 0 0 5px rgba(255, 51, 51, 0.7);
        }
        
        @keyframes pulse-update {
            0% { opacity: 0.8; transform: scale(1); text-shadow: 0 0 5px rgba(255, 51, 51, 0.7); }
            50% { opacity: 1; transform: scale(1.2); color: #ff0000; text-shadow: 0 0 10px rgba(255, 0, 0, 0.9); }
            100% { opacity: 0.8; transform: scale(1); text-shadow: 0 0 5px rgba(255, 51, 51, 0.7); }
        }
    </style>
    
    <script>
        // Sidebar JavaScript Functions
        function toggleSidebar() {
            const sidebar = document.getElementById('sidebar');
            const toggleBtn = document.querySelector('.sidebar-toggle i');
            
            sidebar.classList.toggle('collapsed');
            
            if (sidebar.classList.contains('collapsed')) {
                toggleBtn.className = 'fas fa-chevron-right';
                localStorage.setItem('sidebarCollapsed', 'true');
            } else {
                toggleBtn.className = 'fas fa-chevron-left';
                localStorage.setItem('sidebarCollapsed', 'false');
            }
        }
        
        function toggleMobileSidebar() {
            const sidebar = document.getElementById('sidebar');
            const overlay = document.querySelector('.mobile-overlay');
            
            sidebar.classList.toggle('mobile-open');
            overlay.classList.toggle('active');
        }
        
        function closeMobileSidebar() {
            const sidebar = document.getElementById('sidebar');
            const overlay = document.querySelector('.mobile-overlay');
            
            sidebar.classList.remove('mobile-open');
            overlay.classList.remove('active');
        }
        
        function toggleDropdown(id) {
            const dropdown = document.querySelector(`[data-dropdown="${id}"]`);
            const allDropdowns = document.querySelectorAll('.nav-dropdown');
            
            // Close other dropdowns
            allDropdowns.forEach(d => {
                if (d !== dropdown) {
                    d.classList.remove('open');
                }
            });
            
            // Toggle current dropdown
            dropdown.classList.toggle('open');
        }
        
        // Initialize sidebar state
        document.addEventListener('DOMContentLoaded', function() {
            const sidebarCollapsed = localStorage.getItem('sidebarCollapsed');
            if (sidebarCollapsed === 'true') {
                document.getElementById('sidebar').classList.add('collapsed');
                document.querySelector('.sidebar-toggle i').className = 'fas fa-chevron-right';
            }
            
            // Auto-open active dropdown
            const activeDropdownItem = document.querySelector('.nav-dropdown-item.active');
            if (activeDropdownItem) {
                const dropdown = activeDropdownItem.closest('.nav-dropdown');
                if (dropdown) {
                    dropdown.classList.add('open');
                }
            }
        });
        
        // Close mobile sidebar on window resize
        window.addEventListener('resize', function() {
            if (window.innerWidth > 768) {
                closeMobileSidebar();
            }
        });
    </script>
    <?php
    return ob_get_clean();
}

function getSidebarMenuItems($user_role, $pending_transactions_count = 0) {
    // Determine relative prefix for admin URLs based on current script location
    $scriptPath = $_SERVER['PHP_SELF'] ?? $_SERVER['SCRIPT_NAME'] ?? '';
    $isInAdmin = (strpos($scriptPath, '/admin/') !== false);
    $adminPrefix = $isInAdmin ? '' : 'admin/';

    $menu = [
        [
            'title' => 'মূল মেনু',
            'items' => [
                [
                    'id' => 'dashboard',
                    'text' => 'ড্যাশবোর্ড',
                    'url' => '/bidda/',
                    'icon' => 'fas fa-home'
                ]
            ]
        ]
    ];
    
    // Student: only Results, Fees, Notices
    if ($user_role == 'student') {
        $menu[] = [
            'title' => 'আমার অ্যাকাউন্ট',
            'items' => [
                [
                    'id' => 'my_results',
                    'text' => 'আমার ফলাফল',
                    'url' => 'reports/my_results.php',
                    'icon' => 'fas fa-file-alt'
                ],
                [
                    'id' => 'my_fees',
                    'text' => 'আমার ফি',
                    'url' => 'fees/my_fees.php',
                    'icon' => 'fas fa-money-bill-wave'
                ],
                [
                    'id' => 'fee_selection',
                    'text' => 'ফি নির্বাচন',
                    'url' => 'fees/select_fees.php',
                    'icon' => 'fas fa-list-check'
                ],

                [
                    'id' => 'notices',
                    'text' => 'নোটিশ বোর্ড',
                    'url' => 'notices/index.php',
                    'icon' => 'fas fa-bullhorn'
                ],
                [
                    'id' => 'ai_performance_analyzer',
                    'text' => 'এআই পারফরমেন্স অ্যানালাইজার',
                    'url' => 'ai_performance_analyzer/index.php',
                    'icon' => 'fas fa-brain',
                    'badge' => 'নতুন'
                ]
            ]
        ];
        
        // Add Online Learning section for students
        $menu[] = [
            'title' => 'অনলাইন শিক্ষা',
            'items' => [
                [
                    'id' => 'online_learning',
                    'text' => 'অনলাইন শিক্ষা',
                    'icon' => 'fas fa-laptop',
                    'submenu' => [
                        ['text' => 'ড্যাশবোর্ড', 'url' => 'online_learning/dashboard.php'],
                        ['text' => 'ভার্চুয়াল ক্লাসরুম', 'url' => 'online_learning/virtual_classroom.php'],
                        ['text' => 'অনলাইন পরীক্ষা', 'url' => 'online_learning/online_exams.php'],
                        ['text' => 'অ্যাসাইনমেন্ট', 'url' => 'online_learning/assignments.php'],
                        ['text' => 'লার্নিং মেটেরিয়াল', 'url' => 'online_learning/learning_materials.php']
                    ]
                ]
            ]
        ];
        
        return $menu;
    }
    
    // Reorganized menu structure for admin and teacher roles
    if ($user_role == 'admin' || $user_role == 'teacher') {
        // For teachers, show only relevant academic items
        if ($user_role == 'teacher') {
            // Academic Section - Simplified for teachers
            $menu[] = [
                'title' => 'একাডেমিক',
                'items' => [
                    [
                        'id' => 'my_students',
                        'text' => 'আমার ছাত্র-ছাত্রী',
                        'icon' => 'fas fa-user-graduate',
                        'submenu' => [
                            ['text' => 'নতুন ভর্তি', 'url' => 'students/add.php'],
                            ['text' => 'সব ছাত্র-ছাত্রী', 'url' => 'students/list.php'],
                            ['text' => 'অনুসন্ধান', 'url' => 'students/search.php', 'icon' => 'fas fa-search']
                        ]
                    ],
                    [
                        'id' => 'my_marks',
                        'text' => 'আমার মার্কস',
                        'icon' => 'fas fa-chart-line',
                        'submenu' => [
                            ['text' => 'মার্কস এন্ট্রি', 'url' => 'marks/entry.php'],
                            ['text' => 'ক্লাস ভিত্তিক মার্কস সেটআপ', 'url' => 'marks/class_based_setup.php'],
                            ['text' => 'মার্কস বিভাজন সেটআপ', 'url' => 'marks/setup.php']
                        ]
                    ],
                    [
                        'id' => 'my_exams',
                        'text' => 'আমার পরীক্ষা',
                        'icon' => 'fas fa-clipboard-list',
                        'submenu' => [
                            ['text' => 'পরীক্ষার রুটিন', 'url' => 'exams/routine.php'],
                            ['text' => 'মার্কশীট', 'url' => 'reports/marksheet.php'],
                            ['text' => 'টেবুলেশন শীট', 'url' => 'reports/tabulation_sheet.php'],
                            ['text' => 'ট্রান্সপোজড টেবুলেশন শীট', 'url' => 'reports/transposed_tabulation_sheet.php']
                        ]
                    ],
                    [
                        'id' => 'my_attendance',
                        'text' => 'আমার উপস্থিতি',
                        'icon' => 'fas fa-calendar-check',
                        'submenu' => [
                            ['text' => 'উপস্থিতি নিন', 'url' => 'attendance/mark.php'],
                            ['text' => 'উপস্থিতি রিপোর্ট', 'url' => 'attendance/report.php']
                        ]
                    ]
                ]
            ];
        } else {
            // Academic Section - Full access for admin
            $menu[] = [
                'title' => 'একাডেমিক',
                'items' => [
                    [
                        'id' => 'students',
                        'text' => 'ছাত্র-ছাত্রী',
                        'icon' => 'fas fa-user-graduate',
                        'submenu' => [
                            ['text' => 'নতুন ভর্তি', 'url' => 'students/add.php'],
                            ['text' => 'নতুন ভর্তি (বিষয়সহ, চতুর্থ বিষয় সহ)', 'url' => 'students/add_with_fourth_subject.php', 'icon' => 'fas fa-user-plus', 'badge' => 'নতুন'],
                            ['text' => 'সব ছাত্র-ছাত্রী', 'url' => 'students/list.php'],
                            ['text' => 'অনুসন্ধান', 'url' => 'students/search.php', 'icon' => 'fas fa-search'],
                            ['text' => 'বিষয়সহ তালিকা', 'url' => 'students/students_with_subjects.php', 'icon' => 'fas fa-book-reader', 'badge' => 'নতুন'],
                            ['text' => 'বাল্ক আপলোড', 'url' => 'bulk_upload/students_upload_bengali.php'],
                            ['text' => 'ছাত্র-ছাত্রী ও বিষয় আপলোড', 'url' => 'bulk_upload/students_with_subjects_upload.php', 'icon' => 'fas fa-file-upload', 'badge' => 'নতুন'],
                            ['text' => 'ছাত্র-ছাত্রী ও চতুর্থ বিষয় আপলোড', 'url' => 'bulk_upload/students_with_fourth_subject_upload.php', 'icon' => 'fas fa-file-upload', 'badge' => 'নতুন'],
                            ['text' => 'বাল্ক স্টুডেন্ট আপডেট', 'url' => 'students/bulk_update.php'],

                            ['text' => 'বাল্ক বিষয় নির্বাচন', 'url' => 'students/bulk_subject_selection.php', 'icon' => 'fas fa-book'],
                            ['text' => 'আইডি কার্ড প্রিন্ট', 'url' => 'students/bulk_id_card.php', 'icon' => 'fas fa-id-card'],
                            ['text' => 'প্রত্যয়ন পত্র', 'url' => 'certificates/dashboard.php', 'icon' => 'fas fa-certificate', 'badge' => 'নতুন'],
                            ['text' => 'প্রশংসা পত্র', 'url' => 'certificates/appreciation_certificate.php', 'icon' => 'fas fa-award', 'badge' => 'নতুন'],
                            ['text' => 'গ্রাহক নম্বর তালিকা', 'url' => 'student_customer_list.php', 'icon' => 'fas fa-list'],
                            ['text' => 'বাল্ক রোল সম্পাদনা', 'url' => 'admin/bulk_roll_edit.php', 'icon' => 'fas fa-edit', 'badge' => 'নতুন'],
                            ['text' => 'এআই পারফরমেন্স অ্যানালাইজার', 'url' => 'ai_performance_analyzer/index.php', 'icon' => 'fas fa-brain', 'badge' => 'নতুন'],
                            ['text' => 'গ্যালারি', 'url' => 'students/admin/gallery.php', 'icon' => 'fas fa-images'],
                            ['text' => 'সেটিংস', 'url' => 'students/admin/settings.php', 'icon' => 'fas fa-cog']
                        ]
                    ],
                    [
                        'id' => 'classes',
                        'text' => 'ক্লাস ব্যবস্থাপনা',
                        'icon' => 'fas fa-chalkboard',
                        'submenu' => [
                            ['text' => 'নতুন ক্লাস', 'url' => 'classes/add.php'],
                            ['text' => 'সব ক্লাস', 'url' => 'classes/manage.php'],
                            ['text' => 'ক্লাস আইডি ফাইন্ডার', 'url' => 'subjects/find_class_ids.php', 'icon' => 'fas fa-search'],
                            ['text' => 'ডিরেক্ট ডিলেট', 'url' => 'admin/direct_class_deletion.php', 'icon' => 'fas fa-trash-alt']
                        ]
                    ],
                    [
                        'id' => 'subjects',
                        'text' => 'বিষয়সমূহ',
                        'icon' => 'fas fa-book',
                        'submenu' => [
                            ['text' => 'নতুন বিষয়', 'url' => 'subjects/add.php'],
                            ['text' => 'সব বিষয়', 'url' => 'subjects/list.php'],
                            ['text' => 'বিষয় নির্বাচন তালিকা', 'url' => 'subjects/subject_selection_list.php'],
                            ['text' => 'ক্লাস-বাই-গ্রুপ বিষয় নির্ধারণ', 'url' => 'subjects/assign_by_class.php'],
                            ['text' => 'চতুর্থ বিষয় (উচ্চ মাধ্যমিক)', 'url' => 'students/manage_fourth_subject.php', 'icon' => 'fas fa-star', 'badge' => 'নতুন'],
                            ['text' => 'বিষয়ভিত্তিক বিশ্লেষণ/লিস্ট/সীটকার্ড', 'url' => 'subjects/subject_enrollment_tools.php'],
                            ['text' => 'শিক্ষার্থী ফিল্টার (বিষয় ভিত্তিক)', 'url' => 'subjects/student_filter.php']
                        ]
                    ],
                    [
                        'id' => 'marks',
                        'text' => 'মার্কস সিস্টেম',
                        'icon' => 'fas fa-chart-line',
                        'badge' => 'নতুন',
                        'submenu' => [
                            ['text' => 'ক্লাস ভিত্তিক মার্কস সেটআপ', 'url' => 'marks/class_based_setup.php'],
                            ['text' => 'মার্কস বিভাজন সেটআপ', 'url' => 'marks/setup.php'],
                            ['text' => 'মার্কস এন্ট্রি', 'url' => 'marks/entry.php']
                        ]
                    ],
                    [
                        'id' => 'exams',
                        'text' => 'পরীক্ষা',
                        'icon' => 'fas fa-clipboard-list',
                        'submenu' => [
                            ['text' => 'পরীক্ষার রুটিন', 'url' => 'exams/routine.php'],
                            ['text' => 'হাজিরা পত্র', 'url' => 'exams/attendance.php'],
                            ['text' => 'অনুপস্থিতির তালিকা', 'url' => 'exams/absence_list.php'],
                            ['text' => 'সীট কার্ড', 'url' => 'exams/seat_card.php'],
                            ['text' => 'সীট কার্ড (গ্রিড)', 'url' => 'exams/seat_card_grid.php'],
                            ['text' => 'ডাইনামিক সীট প্ল্যান', 'url' => 'exams/dynamic_seat_plan.php'],
                            ['text' => 'সীট প্ল্যান (আপলোড/কাস্টম)', 'url' => 'exams/upload_seat_plan.php'],
                            ['text' => 'রুম ভিত্তিক ডিউটি', 'url' => 'exams/room_duty.php', 'roles' => ['admin','teacher']],
                            ['text' => 'টিচার-ওয়াইজ ডিউটি লেটার', 'url' => 'exams/teacher_duty_letter.php', 'roles' => ['admin','teacher']]
                        ]
                    ],
                    [
                        'id' => 'reports',
                        'text' => 'রিপোর্ট ও ফলাফল',
                        'icon' => 'fas fa-chart-bar',
                        'submenu' => [
                            ['text' => 'পরিসংখ্যান', 'url' => 'reports/index.php', 'icon' => 'fas fa-chart-pie'],
                            ['text' => 'মার্কশীট', 'url' => 'reports/marksheet.php', 'icon' => 'fas fa-file-signature'],
                            ['text' => 'যশোর বোর্ড এসএসসি মার্কশীট', 'url' => 'jessore_board_ssc_bangla_english_marksheet.php', 'icon' => 'fas fa-graduation-cap', 'badge' => 'নতুন'],
                            ['text' => 'বাল্ক প্রিন্ট (আলাদা ৪র্থ বিষয়)', 'url' => 'reports/bulk_print_marksheets_separate_fourth.php', 'icon' => 'fas fa-print', 'badge' => 'নতুন'],
                            
                            ['text' => 'ট্রান্সপোজড টেবুলেশন শীট', 'url' => 'reports/transposed_tabulation_sheet.php', 'icon' => 'fas fa-table'],
                             ['text' => 'মেরিট পজিশন পিডিএফ', 'url' => 'reports/merit_position_pdf.php', 'icon' => 'fas fa-file-pdf', 'badge' => 'নতুন'],
                            ['text' => 'উপস্থিতি রিপোর্ট', 'url' => 'attendance/report.php', 'icon' => 'fas fa-calendar-alt'],
                            ['text' => 'রেজাল্ট সহ ছাত্র তালিকা', 'url' => 'students_with_results.php', 'icon' => 'fas fa-list-alt', 'badge' => 'নতুন'],
                            ['text' => 'ফলাফল প্রকাশ তারিখ', 'url' => 'results_publication.php', 'icon' => 'fas fa-calendar-check', 'badge' => 'নতুন', 'roles' => ['admin']],
                            ['text' => 'শিক্ষার্থী রিপোর্ট', 'url' => 'reports/students_report.php', 'icon' => 'fas fa-users'],
                            ['text' => 'শিক্ষক রিপোর্ট', 'url' => 'reports/teachers_report.php', 'icon' => 'fas fa-chalkboard-teacher'],
                            ['text' => 'সকল ইউজার রিপোর্ট', 'url' => 'reports/all_users_report.php', 'icon' => 'fas fa-users-cog', 'roles' => ['admin']],
                            ['text' => 'পাবলিক রেজাল্ট সার্চ', 'url' => 'public_report.php', 'icon' => 'fas fa-search'],
                            ['text' => 'পাবলিক ফি/উপস্থিতি সার্চ', 'url' => 'logout.php', 'icon' => 'fas fa-search-dollar'],
                            ['text' => 'বাল্ক মার্কশীট', 'url' => 'reports/all_subjects_marksheet.php', 'icon' => 'fas fa-file-download', 'badge' => 'নতুন'],
                            ['text' => 'বাল্ক প্রিন্ট (সকল বিষয়)', 'url' => 'reports/bulk_print_marksheets.php', 'icon' => 'fas fa-print', 'badge' => 'নতুন'],
                            
                            ['text' => 'বাল্ক মার্কশীট প্রিন্টার', 'url' => 'reports/bulk_print_marksheets.php', 'icon' => 'fas fa-print', 'badge' => 'নতুন'],
                            ['text' => 'আলাদা বাংলা & ইংরেজি মার্কশীট', 'url' => 'reports/combined_bangla_english_marksheet.php', 'icon' => 'fas fa-file-alt', 'badge' => 'নতুন'],
                            
                            ['text' => 'পাশ/ফেল তালিকা', 'url' => 'reports/pass_fail_report.php', 'icon' => 'fas fa-chart-pie', 'roles' => ['admin', 'teacher']],
                            ['text' => '৪র্থ বিষয়সহ ফলাফল', 'url' => 'reports/fourth_subject_gpa_report.php', 'icon' => 'fas fa-graduation-cap', 'roles' => ['admin', 'teacher']],
                           ['text' => 'টেবুলেশন শীট', 'url' => 'reports/tabulation_sheet.php', 'icon' => 'fas fa-table'],
                        ]
                    ],
                    [
                        'id' => 'attendance',
                        'text' => 'উপস্থিতি',
                        'icon' => 'fas fa-calendar-check',
                        'submenu' => [
                            ['text' => 'উপস্থিতি নিন', 'url' => 'attendance/mark.php'],
                            ['text' => 'উপস্থিতি দেখুন', 'url' => 'attendance/view.php'],
                            ['text' => 'উপস্থিতি রিপোর্ট', 'url' => 'attendance/report.php'],
                                                        ['text' => 'বিস্তারিত উপস্থিতি রিপোর্ট', 'url' => 'attendance/comprehensive_report.php', 'icon' => 'fas fa-file-alt', 'badge' => 'নতুন'],
                            ['text' => 'উপস্থিতি ড্যাশবোর্ড', 'url' => 'attendance_dashboard/', 'icon' => 'fas fa-dashboard', 'badge' => 'নতুন']
                        ]
                    ],
                    [
                        'id' => 'attendance_advanced',
                        'text' => 'উপস্থিতি (উন্নত)',
                        'icon' => 'fas fa-calendar-alt',
                        'submenu' => [
                            ['text' => 'ড্যাশবোর্ড', 'url' => 'attendance_dashboard/dashboard.php', 'icon' => 'fas fa-dashboard'],
                            ['text' => 'অটো স্ক্যান রেকর্ড', 'url' => 'attendance_dashboard/auto_attendance.php', 'icon' => 'fas fa-camera', 'badge' => 'নতুন'],
                            ['text' => 'অটো উপস্থিতি (শিক্ষক)', 'url' => 'attendance_dashboard/auto_attendance_teacher.php', 'icon' => 'fas fa-chalkboard-teacher', 'badge' => 'নতুন'],
                            ['text' => 'কনফিগারেশন', 'url' => 'attendance_dashboard/config.php', 'icon' => 'fas fa-cog'],
                            ['text' => 'মেসেজিং কনফিগারেশন', 'url' => 'attendance_dashboard/messaging_config.php', 'icon' => 'fas fa-comment-dots'],
                            ['text' => 'বায়োমেট্রিক রেজিস্ট্রেশন', 'url' => 'attendance_dashboard/register_biometric.php', 'icon' => 'fas fa-fingerprint'],
                            ['text' => 'ছাত্র ফটো রেজিস্ট্রেশন', 'url' => 'attendance_dashboard/photo_registration.php', 'icon' => 'fas fa-camera'],
                            ['text' => 'শিক্ষক ফটো রেজিস্ট্রেশন', 'url' => 'attendance_dashboard/teacher_photo_registration.php', 'icon' => 'fas fa-chalkboard-teacher'],
                            ['text' => 'ক্যামেরা সহায়তা', 'url' => 'attendance_dashboard/camera_help.php', 'icon' => 'fas fa-video', 'badge' => 'নতুন']
                        ]
                    ],
                    [
                        'id' => 'all_subjects_marksheet',
                        'text' => 'সকল বিষয়ের মার্কশীট',
                        'url' => 'reports/all_subjects_marksheet.php',
                        'icon' => 'fas fa-file-alt',
                        'badge' => 'নতুন'
                    ],
                    [
                        'id' => 'custom_draggable_marksheet',
                        'text' => 'কাস্টম ড্র্যাগ-এবল মার্কশীট',
                        'url' => 'reports/custom_draggable_marksheet.php',
                        'icon' => 'fas fa-grip-vertical',
                        'badge' => 'নতুন'
                    ]
                ]
            ];
        }
        
        // Accounting Section
        if ($user_role == 'admin') {
            $menu[] = [
                'title' => 'একাউন্টিং',
                'items' => [
                    [
                        'id' => 'fee_management',
                        'text' => 'ফি ব্যবস্থাপনা',
                        'url' => 'fees/management_dashboard.php',
                        'icon' => 'fas fa-cog'
                    ],
                    [
                        'id' => 'expense_management',
                        'text' => 'ব্যয় ব্যবস্থাপনা',
                        'icon' => 'fas fa-wallet',
                        'submenu' => [
                            ['text' => 'ব্যয় ক্যাটাগরি', 'url' => 'expenses/categories.php', 'icon' => 'fas fa-tags'],
                            ['text' => 'ব্যয় যোগ করুন', 'url' => 'expenses/expenses.php', 'icon' => 'fas fa-plus-circle'],
                            ['text' => 'ব্যয় রিপোর্ট', 'url' => 'expenses/reports.php', 'icon' => 'fas fa-chart-bar'],
                            ['text' => 'আয় রিপোর্ট', 'url' => 'fees/income_report.php', 'icon' => 'fas fa-chart-line'],
                            ['text' => 'আয়-ব্যয় তুলনা', 'url' => 'expenses/income_expense_report.php', 'icon' => 'fas fa-balance-scale'],
                            ['text' => 'ট্র্যানজেকশন বিশ্লেষণ', 'url' => 'expenses/transaction_analysis.php', 'icon' => 'fas fa-chart-pie'],
                            ['text' => 'পূর্ববর্তী ব্যালেন্স', 'url' => 'previous_balance.php', 'icon' => 'fas fa-balance-scale']
                        ]
                    ],
                    [
                        'id' => 'fee_collection',
                        'text' => 'ফি সংগ্রহ',
                        'icon' => 'fas fa-money-bill-wave',
                        'submenu' => [
                            ['text' => 'ফি সংগ্রহ', 'url' => 'fees/student_fees.php', 'icon' => 'fas fa-money-bill-wave'],
                            ['text' => 'ফি ড্যাশবোর্ড', 'url' => 'fees/new_dashboard.php', 'icon' => 'fas fa-tachometer-alt'],
                            ['text' => 'ফি নির্ধারণ', 'url' => 'fees/manage.php'],
                            ['text' => 'কাস্টম ফি নির্ধারণ', 'url' => 'fees/custom_assign.php'],
                            ['text' => 'দ্রুত কালেক্ট', 'url' => 'fees/collect.php'],
                            ['text' => 'ফি পেমেন্ট ড্যাশবোর্ড', 'url' => 'fees/fee_payment_dashboard.php', 'icon' => 'fas fa-credit-card'],
                            ['text' => 'বিল সাবমিশন', 'url' => 'fees/bill_submission.php'],
                            ['text' => 'ইনভয়েজ তৈরি', 'url' => 'fees/invoice.php'],
                            ['text' => 'ফি রিপোর্ট', 'url' => 'fees/reports.php'],
                            ['text' => 'bKash পেমেন্ট সেটিংস', 'url' => 'admin/bKash_settings.php'],
                            ['text' => 'Zashof পেমেন্ট সেটিংস', 'url' => 'admin/zashof_settings.php'],
                            ['text' => 'ZiniPay সেটিংস', 'url' => 'admin/zinipay_settings.php', 'icon' => 'fas fa-mobile-alt'],
                            ['text' => 'ব্যাংক অ্যাকাউন্টস', 'url' => 'admin/bank_accounts.php'],
                            ['text' => 'ব্যাংক ট্রানজেকশন ম্যানেজ', 'url' => 'admin/bank_transactions.php'],
                            ['text' => 'ব্যাংক ডিপোজিট জমা', 'url' => 'admin/submit_bank_deposit.php'],
                            ['text' => 'ব্যাংক ট্রানজেকশন ভেরিফাই', 'url' => 'fees/verify_bank_transactions.php', 'badge' => $pending_transactions_count > 0 ? $pending_transactions_count : null]
                        ]
                    ]
                ]
            ];
        } else if ($user_role == 'teacher') {
            // Simplified accounting section for teachers
            $menu[] = [
                'title' => 'একাউন্টিং',
                'items' => [
                    [
                        'id' => 'teacher_fee_collection',
                        'text' => 'ফি সংগ্রহ',
                        'icon' => 'fas fa-money-bill-wave',
                        'submenu' => [
                            ['text' => 'ফি সংগ্রহ', 'url' => 'fees/student_fees.php'],
                            ['text' => 'ফি পেমেন্ট ড্যাশবোর্ড', 'url' => 'fees/fee_payment_dashboard.php'],
                            ['text' => 'ফি রিপোর্ট', 'url' => 'fees/reports.php']
                        ]
                    ]
                ]
            ];
        }
        
        // Teacher Section
        if ($user_role == 'admin') {
            $menu[] = [
                'title' => 'টিচার',
                'items' => [
                    [
                        'id' => 'teachers',
                        'text' => 'শিক্ষকমণ্ডলী',
                        'icon' => 'fas fa-chalkboard-teacher',
                        'submenu' => [
                            ['text' => 'নতুন শিক্ষক', 'url' => 'teachers/add.php'],
                            ['text' => 'সব শিক্ষক', 'url' => 'teachers/list.php'],
                            ['text' => 'ক্লাস রুটিন', 'url' => 'teachers/routine.php'],
                            ['text' => 'শিক্ষকের ডিউটি ম্যানেজমেন্ট', 'url' => 'admin/teacher_duties.php', 'icon' => 'fas fa-balance-scale', 'badge' => 'নতুন'],
                            ['text' => 'বাল্ক আপলোড', 'url' => 'bulk_upload/teachers_upload_bengali.php'],
                            ['text' => 'শিক্ষকের বিষয় নির্ধারণ', 'url' => 'admin/teacher_subject_assignment.php', 'icon' => 'fas fa-book-reader']
                        ]
                    ]
                ]
            ];
        } else if ($user_role == 'teacher') {
            // For teachers, show only the most relevant items
            $menu[] = [
                'title' => 'আমার কাজসমূহ',
                'items' => [
                    [
                        'id' => 'teacher_dashboard',
                        'text' => 'আমার ড্যাশবোর্ড',
                        'url' => 'teachers/dashboard.php',
                        'icon' => 'fas fa-tachometer-alt'
                    ],
                    [
                        'id' => 'my_students',
                        'text' => 'আমার ছাত্র-ছাত্রী',
                        'icon' => 'fas fa-user-graduate',
                        'submenu' => [
                            ['text' => 'তালিকা দেখুন', 'url' => 'teachers/my_students.php'],
                            ['text' => 'নতুন ভর্তি', 'url' => 'teachers/add_student.php'],
                            ['text' => 'নতুন ভর্তি (বিষয়সহ, চতুর্থ বিষয় সহ)', 'url' => 'students/add_with_fourth_subject.php', 'icon' => 'fas fa-user-plus', 'badge' => 'নতুন'],
                            ['text' => 'বাল্ক ছাত্র আপলোড', 'url' => 'teachers/bulk_upload_students.php'],
                            ['text' => 'ছাত্র-ছাত্রী ও চতুর্থ বিষয় আপলোড', 'url' => 'bulk_upload/students_with_fourth_subject_upload.php', 'icon' => 'fas fa-file-upload', 'badge' => 'নতুন'],
                            ['text' => 'গ্রাহক নম্বর তালিকা', 'url' => 'student_customer_list.php', 'icon' => 'fas fa-list']
                        ]
                    ],
                    [
                        'id' => 'my_classes',
                        'text' => 'আমার ক্লাসসমূহ',
                        'icon' => 'fas fa-chalkboard',
                        'submenu' => [
                            ['text' => 'ক্লাস রুটিন', 'url' => 'teachers/routine.php'],
                            ['text' => 'উপস্থিতি নিন', 'url' => 'teachers/attendance.php'],
                                                        ['text' => 'বিস্তারিত উপস্থিতি রিপোর্ট', 'url' => 'attendance/comprehensive_report.php', 'icon' => 'fas fa-file-alt', 'badge' => 'নতুন'],
                            ['text' => 'মার্কস এন্ট্রি', 'url' => 'teachers/marks_entry.php'],
                            ['text' => 'ছুটির আবেদন', 'url' => 'teachers/leave_application.php', 'icon' => 'fas fa-calendar-plus']
                        ]
                    ],
                    [
                        'id' => 'my_exams',
                        'text' => 'আমার পরীক্ষা',
                        'icon' => 'fas fa-clipboard-list',
                        'submenu' => [
                            ['text' => 'মার্কস এন্ট্রি', 'url' => 'teachers/marks_entry.php'],
                            ['text' => 'মার্কশীট', 'url' => 'teachers/my_reports.php?report_type=marksheet'],
                            ['text' => 'টেবুলেশন শীট', 'url' => 'teachers/my_reports.php?report_type=tabulation'],
                            ['text' => 'ট্রান্সপোজড টেবুলেশন শীট', 'url' => 'reports/transposed_tabulation_sheet.php']
                        ]
                    ]
                ]
            ];
        }
        
        // Security Section (Admin only)
        if ($user_role == 'admin') {
            $menu[] = [
                'title' => 'সিকিউরিটি',
                'items' => [
                    [
                        'id' => 'admin',
                        'text' => 'অ্যাডমিন প্যানেল',
                        'icon' => 'fas fa-shield-alt',
                        'submenu' => [
                            ['text' => 'ব্যবহারকারী', 'url' => $adminPrefix . 'users.php'],
                            ['text' => 'শিক্ষার্থী অ্যাকাউন্ট ফিক্স', 'url' => $adminPrefix . 'fix_student_accounts.php', 'icon' => 'fas fa-user-graduate', 'badge' => 'নতুন'],
                            ['text' => 'ব্যাংক রসিদ সেটিংস', 'url' => $adminPrefix . 'bank_receipt_settings.php', 'icon' => 'fas fa-file-invoice', 'badge' => 'নতুন'],
                            ['text' => 'সেটিংস', 'url' => $adminPrefix . 'settings.php'],
                            ['text' => 'SMS সেটিংস', 'url' => $adminPrefix . 'sms_settings.php'],


                            ['text' => 'সেশন', 'url' => $adminPrefix . 'sessions.php'],
                            ['text' => 'শাখা', 'url' => $adminPrefix . 'branches.php', 'icon' => 'fas fa-code-branch'],
                            ['text' => 'সেশন ডায়াগনস্টিক', 'url' => 'subjects/check_sessions.php', 'icon' => 'fas fa-search'],
                            ['text' => 'গ্যালারী', 'url' => $adminPrefix . 'gallery.php'],
                            ['text' => 'ভর্তি আবেদন', 'url' => $adminPrefix . 'admission_applications.php'],
                            ['text' => 'ভর্তি তারিখ নির্ধারণ', 'url' => $adminPrefix . 'admission_publish_dates.php', 'icon' => 'fas fa-calendar-alt', 'badge' => 'নতুন'],
                            ['text' => 'ছুটির আবেদন', 'url' => $adminPrefix . 'leave_applications.php', 'icon' => 'fas fa-calendar-plus', 'badge' => 'নতুন'],
                            ['text' => 'ব্যাকআপ', 'url' => $adminPrefix . 'backup.php'],
                            ['text' => 'রিসেট ও প্রোমোশন', 'url' => $adminPrefix . 'reset_promote.php'],
                            ['text' => 'Reset Student Data', 'url' => $adminPrefix . 'reset_student_data.php'],
                            ['text' => 'Reset Teacher Data', 'url' => $adminPrefix . 'reset_teacher_data.php'],
                            ['text' => 'Reset Class Data', 'url' => $adminPrefix . 'reset_class_data.php'],
                            ['text' => 'Direct Class Deletion', 'url' => $adminPrefix . 'direct_class_deletion.php'],
                            ['text' => 'কাস্টম অপশন', 'url' => $adminPrefix . 'custom_options.php'],
                            ['text' => 'ব্যাংক ট্রানজেকশন রিসেট', 'url' => $adminPrefix . 'reset_bank_transactions.php', 'icon' => 'fas fa-trash-alt'],
                            ['text' => 'আয়-ব্যয় ডেটা রিসেট', 'url' => $adminPrefix . 'reset_transactions.php', 'icon' => 'fas fa-undo', 'badge' => 'নতুন'],

                        ]
                    ],
                    [
                        'id' => 'academic_calendar',
                        'text' => 'একাডেমিক ক্যালেন্ডার',
                        'url' => $adminPrefix . 'academic_calendar.php',
                        'icon' => 'fas fa-calendar-alt'
                    ],
                    [
                        'id' => 'messages',
                        'text' => 'বার্তা ব্যবস্থাপনা',
                        'icon' => 'fas fa-comment-dots',
                        'submenu' => [
                            ['text' => 'বার্তা তালিকা', 'url' => $adminPrefix . 'messages.php'],
                            ['text' => 'নন-মাস্কিং মেসেজ পাঠান', 'url' => $adminPrefix . 'send_non_musking_message.php'],
                            ['text' => 'মেসেজ লগ', 'url' => $adminPrefix . 'message_logs.php'],
                            ['text' => 'এসএমএস নোটিফিকেশন সেটিংস', 'url' => $adminPrefix . 'sms_notification_settings.php', 'icon' => 'fas fa-bell', 'badge' => 'নতুন']
                        ]
                    ],
                    [
                        'id' => 'management_board',
                        'text' => 'পরিচালনা পর্ষদ',
                        'url' => $adminPrefix . 'management_board.php',
                        'icon' => 'fas fa-users'
                    ],
                    [
                        'id' => 'exam_committee',
                        'text' => 'পরীক্ষা কমিটি',
                        'url' => $adminPrefix . 'exam_committee.php',
                        'icon' => 'fas fa-users-cog'
                    ],
                    [
                        'id' => 'site_settings',
                        'text' => 'সাইট সেটিংস',
                        'url' => $adminPrefix . 'site_settings.php',
                        'icon' => 'fas fa-cog'
                    ],
                    [
                        'id' => 'watermark_settings',
                        'text' => 'ওয়াটারমার্ক সেটিংস',
                        'url' => $adminPrefix . 'watermark_settings.php',
                        'icon' => 'fas fa-tint'
                    ],
                    [
                        'id' => 'branding_settings',
                        'text' => 'ব্র্যান্ডিং সেটিংস',
                        'url' => $adminPrefix . 'branding_settings.php',
                        'icon' => 'fas fa-paint-brush'
                    ],
                    [
                        'id' => 'customize_school_name',
                        'text' => 'স্কুল নাম কাস্টমাইজ করুন',
                        'url' => 'customize_school_name.php',
                        'icon' => 'fas fa-font'
                    ]
                ]
            ];
        }
        
        // New Features Section - Available for both admin and teacher
        $menu[] = [
            'title' => 'নতুন ফিচার',
            'items' => [
                [
                    'id' => 'transport',
                    'text' => '🚌 পরিবহন ব্যবস্থাপনা',
                    'icon' => 'fas fa-bus',
                    'badge' => 'নতুন',
                    'submenu' => [
                        ['text' => 'বাস তালিকা', 'url' => $adminPrefix . 'transport/buses.php', 'icon' => 'fas fa-bus'],
                        ['text' => 'রুট ব্যবস্থাপনা', 'url' => $adminPrefix . 'transport/bus_routes.php', 'icon' => 'fas fa-route'],
                        ['text' => 'ছাত্র সাবস্ক্রিপশন', 'url' => $adminPrefix . 'transport/bus_subscriptions.php', 'icon' => 'fas fa-users'],
                        ['text' => 'বাস উপস্থিতি', 'url' => $adminPrefix . 'transport/bus_attendance.php', 'icon' => 'fas fa-clipboard-check']
                    ]
                ],
                [
                    'id' => 'hostel',
                    'text' => '🏠 হোস্টেল ব্যবস্থাপনা',
                    'icon' => 'fas fa-home',
                    'badge' => 'নতুন',
                    'submenu' => [
                        ['text' => 'হোস্টেল ড্যাশবোর্ড', 'url' => $adminPrefix . 'hostel/index.php', 'icon' => 'fas fa-home'],
                        ['text' => 'ভবন ও রুম', 'url' => $adminPrefix . 'hostel/rooms.php', 'icon' => 'fas fa-building'],
                        ['text' => 'ছাত্র বরাদ্দ', 'url' => $adminPrefix . 'hostel/allocations.php', 'icon' => 'fas fa-user-plus'],
                        ['text' => 'হোস্টেল ফি', 'url' => $adminPrefix . 'hostel/hostel_fees.php', 'icon' => 'fas fa-money-bill']
                    ]
                ],
                [
                    'id' => 'lms',
                    'text' => '📚 অনলাইন ক্লাস / LMS',
                    'icon' => 'fas fa-graduation-cap',
                    'badge' => 'নতুন',
                    'submenu' => [
                        ['text' => 'LMS ড্যাশবোর্ড', 'url' => $adminPrefix . 'lms/index.php', 'icon' => 'fas fa-tachometer-alt'],
                        ['text' => 'কোর্স ব্যবস্থাপনা', 'url' => $adminPrefix . 'lms/courses.php', 'icon' => 'fas fa-book'],
                        ['text' => 'লাইভ ক্লাস', 'url' => $adminPrefix . 'lms/live_classes.php', 'icon' => 'fas fa-video'],
                        ['text' => 'অ্যাসাইনমেন্ট', 'url' => $adminPrefix . 'lms/assignments.php', 'icon' => 'fas fa-tasks'],
                        ['text' => 'ছাত্রের অগ্রগতি', 'url' => $adminPrefix . 'lms/student_progress.php', 'icon' => 'fas fa-chart-line']
                    ]
                ],
                [
                    'id' => 'backup',
                    'text' => '💾 ব্যাকআপ সিস্টেম',
                    'url' => $adminPrefix . 'backup/index.php',
                    'icon' => 'fas fa-hdd',
                    'badge' => 'নতুন'
                ],
                [
                    'id' => 'audit',
                    'text' => '🔍 অডিট ট্রেইল',
                    'url' => $adminPrefix . 'audit/index.php',
                    'icon' => 'fas fa-search',
                    'badge' => 'নতুন'
                ],
                [
                    'id' => 'parent_portal',
                    'text' => '👨‍👩‍👧 অভিভাবক পোর্টাল',
                    'url' => 'parent_login.php',
                    'icon' => 'fas fa-user-tie',
                    'badge' => 'নতুন'
                ]
            ]
        ];
    }
    
    // Common sections for all users
    $menu[] = [
        'title' => 'অন্যান্য',
        'items' => [
            [
                'id' => 'online_learning',
                'text' => 'অনলাইন শিক্ষা',
                'icon' => 'fas fa-laptop',
                'submenu' => [
                    ['text' => 'ড্যাশবোর্ড', 'url' => 'online_learning/dashboard.php'],
                    ['text' => 'ভার্চুয়াল ক্লাসরুম', 'url' => 'online_learning/virtual_classroom.php'],
                    ['text' => 'অনলাইন পরীক্ষা', 'url' => 'online_learning/online_exams.php'],
                    ['text' => 'অ্যাসাইনমেন্ট', 'url' => 'online_learning/assignments.php'],
                    ['text' => 'লার্নিং মেটেরিয়াল', 'url' => 'online_learning/learning_materials.php']
                ]
            ]
        ]
    ];
    
    // Add additional items based on user role to the 'অন্যান্য' section
    if ($user_role == 'admin') {
        $menu[count($menu)-1]['items'][] = [
            'id' => 'library',
            'text' => 'লাইব্রেরি',
            'url' => 'library/index.php',
            'icon' => 'fas fa-book-open'
        ];
        
        $menu[count($menu)-1]['items'][] = [
            'id' => 'notices',
            'text' => 'নোটিশ বোর্ড',
            'url' => 'notices/index.php',
            'icon' => 'fas fa-bullhorn'
        ];
        
        $menu[count($menu)-1]['items'][] = [
            'id' => 'student_portal',
            'text' => 'স্টুডেন্ট পোর্টাল',
            'url' => 'student_portal.php',
            'icon' => 'fas fa-user-graduate'
        ];
        
        $menu[count($menu)-1]['items'][] = [
            'id' => 'events',
            'text' => 'ইভেন্টস',
            'url' => 'events.php',
            'icon' => 'fas fa-calendar-alt'
        ];
        
        $menu[count($menu)-1]['items'][] = [
            'id' => 'csv_download',
            'text' => 'CSV ডাউনলোড',
            'url' => 'csv_download.php',
            'icon' => 'fas fa-file-csv'
        ];
        
        $menu[count($menu)-1]['items'][] = [
            'id' => 'academic_calendar_view',
            'text' => 'একাডেমিক ক্যালেন্ডার',
            'url' => 'academic_calendar_view.php',
            'icon' => 'fas fa-calendar-check'
        ];
    } else if ($user_role == 'teacher') {
        $menu[count($menu)-1]['items'][] = [
            'id' => 'notices',
            'text' => 'নোটিশ বোর্ড',
            'url' => 'notices/index.php',
            'icon' => 'fas fa-bullhorn'
        ];
        
        $menu[count($menu)-1]['items'][] = [
            'id' => 'events',
            'text' => 'ইভেন্টস',
            'url' => 'events.php',
            'icon' => 'fas fa-calendar-alt'
        ];
        
        $menu[count($menu)-1]['items'][] = [
            'id' => 'csv_download',
            'text' => 'CSV ডাউনলোড',
            'url' => 'csv_download.php',
            'icon' => 'fas fa-file-csv'
        ];
    } else if ($user_role == 'student') {
        $menu[count($menu)-1]['items'][] = [
            'id' => 'library',
            'text' => 'লাইব্রেরি',
            'url' => 'library/index.php',
            'icon' => 'fas fa-book-open'
        ];
        
        $menu[count($menu)-1]['items'][] = [
            'id' => 'notices',
            'text' => 'নোটিশ বোর্ড',
            'url' => 'notices/index.php',
            'icon' => 'fas fa-bullhorn'
        ];
        
        $menu[count($menu)-1]['items'][] = [
            'id' => 'student_portal',
            'text' => 'স্টুডেন্ট পোর্টাল',
            'url' => 'student_portal.php',
            'icon' => 'fas fa-user-graduate'
        ];
        
        $menu[count($menu)-1]['items'][] = [
            'id' => 'csv_download',
            'text' => 'CSV ডাউনলোড',
            'url' => 'csv_download.php',
            'icon' => 'fas fa-file-csv'
        ];
        
        $menu[count($menu)-1]['items'][] = [
            'id' => 'academic_calendar_view',
            'text' => 'একাডেমিক ক্যালেন্ডার',
            'url' => 'academic_calendar_view.php',
            'icon' => 'fas fa-calendar-check'
        ];
    }
    
    return $menu;
}

function getRoleDisplayName($role) {
    switch ($role) {
        case 'admin': return 'প্রশাসক';
        case 'teacher': return 'শিক্ষক';
        case 'student': return 'ছাত্র/ছাত্রী';
        default: return 'ব্যবহারকারী';
    }
}

function isActivePage($url, $current_page) {
    if (empty($current_page)) return false;
    
    // Remove query parameters for comparison
    $url_path = parse_url($url, PHP_URL_PATH);
    $current_path = parse_url($current_page, PHP_URL_PATH);
    
    return basename($url_path) === basename($current_path);
}
?>
