
<div class="app-sidebar-menu">
    <div class="h-100" data-simplebar>
        <!--- Sidemenu -->
        <div id="sidebar-menu">
            <div class="logo-box d-flex align-items-center justify-content-start">
                <a href="<?= base_url('Dashboard') ?>" class="logo logo-dark">
                    <span class="logo-sm">
                        <img src="assets/images/logo.png" alt="" height="22">
                    </span>
                    <span class="logo-lg">
                        <img src="assets/images/logo.png" alt="" height="24">
                    </span>
                </a>
                <span class="text-primary ms-2 fw-bold d-none d-sm-block">
                    GLOBAL POST
                </span>
            </div>

            <ul id="side-menu">
                <li class="menu-title">Menu</li>

                <!-- Dashboard -->
                <li>
                    <a href="<?= base_url('Dashboard') ?>" class="tp-link <?= ($this->uri->segment(1) == '' || $this->uri->segment(1) == 'Dashboard') ? 'active' : '' ?>">
                        <i data-feather="home"></i>
                        <span>Tableau de bord</span>
                    </a>
                </li>

                <!-- Nouveau document -->
                <li>
                    <a href="<?= base_url('Document') ?>" class="tp-link <?= ($this->uri->segment(1) == 'Document') ? 'active' : '' ?>">
                        <i data-feather="edit"></i>
                        <span>Nouveau document</span>
                    </a>
                </li>

                <!-- Documents envoyés -->
                <li>
                    <a href="<?= base_url('File') ?>" class="tp-link <?= ($this->uri->segment(1) == 'File') ? 'active' : '' ?>">
                        <i data-feather="save"></i>
                        <span>Documents enregistrés</span>
                    </a>
                </li>

                <!-- Boite de réception WITH BADGE -->
                <li>
                    <a href="<?= base_url('Boite_reception') ?>" class="tp-link <?= ($this->uri->segment(1) == 'Boite_reception') ? 'active' : '' ?>">
                        <i data-feather="inbox"></i>
                        <span>Boite de réception</span>
                       
                        <span class="menu-badge badge-inbox"></span>
                       
                    </a>
                </li>



                


                   











            

                <!-- ========== MENU DÉPARTEMENT (DYNAMIQUE) ========== -->
                <?php if (isset($membership) && isset($membership['has_department']) && $membership['has_department'] && isset($membership['department_id'])): 
                    $dept_id = $membership['department_id'];
                    $dept_name = isset($membership['department_name']) ? $membership['department_name'] : 'Mon département';
                ?>
                <li>
                    <a href="<?= base_url('department/files/' . $dept_id) ?>" class="tp-link">
                        <i data-feather="briefcase"></i>
                        <span><?= htmlspecialchars($dept_name) ?></span>
                        <?php if (isset($membership['department_unread']) && $membership['department_unread'] > 0): ?>
                        <span class="menu-badge badge-dept"><?= $membership['department_unread'] ?></span>
                        <?php endif; ?>
                    </a>
                </li>
                <?php endif; ?>




                <!-- Fichiers partagés WITH BADGE -->
                <li>
                    <a href="<?= base_url('Shared_files') ?>" class="tp-link <?= ($this->uri->segment(1) == 'Shared_files') ? 'active' : '' ?>">
                        <i data-feather="share-2"></i>
                        <span>Fichiers partagés</span>
                       
                        <span class="menu-badge badge-shared"></span>
                       
                    </a>
                </li>

                <!-- Demandes des congés WITH BADGE -->
                <li>
                    <a href="<?= base_url('Files_by_type') ?>" class="tp-link <?= ($this->uri->segment(1) == 'Files_by_type') ? 'active' : '' ?>">
                        <i data-feather="calendar"></i>
                        <span>Demandes des congés</span>
                        
                        <span class="menu-badge badge-conge"></span>
                        
                    </a>
                </li>

                <!-- Archives -->
                <li>
                    <a href="<?= base_url('Archives') ?>" class="tp-link <?= ($this->uri->segment(1) == 'Archives') ? 'active' : '' ?>">
                        <i data-feather="archive"></i>
                        <span>Archives</span>
                       
                        <span class="menu-badge badge-archive"></span>
                        
                    </a>
                </li>

                <!-- Corbeille -->
                <li>
                    <a href="<?= base_url('Corbeille') ?>" class="tp-link <?= ($this->uri->segment(1) == 'Corbeille') ? 'active' : '' ?>">
                        <i data-feather="trash-2"></i>
                        <span>Corbeille</span>
                        
                        <span class="menu-badge badge-trash"></span>
                        
                    </a>
                </li>

                <li class="menu-title">Configuration</li>

                <!-- Paramètres with Submenu -->
                <?php 
                $parametres_pages = ['Departements', 'Utilisateurs', 'Types_documents', 'Groupes', 'Types_conges', 'DB_Backup'];
                $current_page = $this->uri->segment(1);
                $is_parametres_active = in_array($current_page, $parametres_pages);
                ?>
                
                <li>
                    <a href="#sidebarAuth" data-bs-toggle="collapse" aria-expanded="<?= $is_parametres_active ? 'true' : 'false' ?>" class="tp-link <?= $is_parametres_active ? 'active' : '' ?>">
                        <i data-feather="settings"></i>
                        <span>Paramètres</span>
                        <span class="menu-arrow">▶</span>
                    </a>
                    <div class="collapse <?= $is_parametres_active ? 'show' : '' ?>" id="sidebarAuth">
                        <ul class="nav-second-level">
                            <li>
                                <a href="<?= base_url('Departement') ?>" class="tp-link <?= ($current_page == 'Departement') ? 'active' : '' ?>">
                                    <i data-feather="layers"></i> Départements
                                </a>
                            </li>
                            <li>
                                <a href="<?= base_url('User') ?>" class="tp-link <?= ($current_page == 'User') ? 'active' : '' ?>">
                                    <i data-feather="users"></i> Utilisateurs
                                </a>
                            </li>
                            <li>
                                <a href="<?= base_url('Document_type') ?>" class="tp-link <?= ($current_page == 'Document_type') ? 'active' : '' ?>">
                                    <i data-feather="file"></i> Types de documents
                                </a>
                            </li>
                            <li>
                                <a href="<?= base_url('Group') ?>" class="tp-link <?= ($current_page == 'Group') ? 'active' : '' ?>">
                                    <i data-feather="grid"></i> Groupes
                                </a>
                            </li>
                            <li>
                                <a href="<?= base_url('User_group') ?>" class="tp-link <?= ($current_page == 'User_group') ? 'active' : '' ?>">
                                    <i data-feather="grid"></i> Membres des Gpes
                                </a>
                            </li>
                            <li>
                                <a href="<?= base_url('Leave_type') ?>" class="tp-link <?= ($current_page == 'Leave_type') ? 'active' : '' ?>">
                                    <i data-feather="clock"></i> Types de congés
                                </a>
                            </li>
                            
                            <li>
                                <a href="<?= base_url('DB_Backup') ?>" class="tp-link <?= ($current_page == 'DB_Backup') ? 'active' : '' ?>">
                                    <i data-feather="database"></i> DB Backup
                                </a>
                            </li>
                        </ul>
                    </div>
                </li>
            </ul>
        </div>
        <!-- End Sidebar -->
        <div class="clearfix"></div>
    </div>
</div>
