<!-- Sidebar Start -->
<?php
$session = session();
$current_controller = service('uri')->getSegment(2);
$current_method = service('uri')->getSegment(3);

// Define active states for each menu based on exact controller or method
$activeCommon = ($current_controller === 'menu');
$activeDepartments = ($current_controller === 'departments');
$activeLibrary = ($current_controller === 'library');
$activeInterpages = ($current_controller === 'page-contents' || $current_controller === 'page-media');
$activeContacts = ($current_controller === 'contacts');
$activeHome = ($current_controller === 'home-services' || $current_controller === 'home-academic-programs' || $current_controller === 'home-tender-notices');

?>

<nav class="sidebar sidebar-offcanvas" id="sidebar">
  <ul class="nav" id="sidebar-accordion">

    <li class="nav-item nav-profile">
      <a href="#" class="nav-link">
        <div class="nav-profile-image">
          <img src="<?= base_url('assets/backdesk/img/user.png') ?>" alt="profile" />
          <span class="login-status online"></span>
        </div>
        <div class="nav-profile-text d-flex flex-column">
          <span class="font-weight-bold mb-2"><?= esc($session->get('name')) ?></span>
          <span class="text-secondary text-small">Admin</span>
        </div>
        <i class="mdi mdi-bookmark-check text-success nav-profile-badge"></i>
      </a>
    </li>

    <hr>

    <!-- Dashboard (single link) -->
    <li class="nav-item">
      <a class="nav-link <?= ($current_controller === 'dashboard') ? 'active' : '' ?>" href="<?= base_url('backdesk/dashboard') ?>">
        <span class="menu-title">Dashboard</span>
        <i class="mdi mdi-home menu-icon"></i>
      </a>
    </li>

    <!-- Common -->
    <li class="nav-item">
      <a class="nav-link <?= $activeCommon ? 'active' : '' ?>" data-bs-toggle="collapse" href="#common" aria-expanded="<?= $activeCommon ? 'true' : 'false' ?>" aria-controls="common">
        <span class="menu-title">Common</span>
        <i class="menu-arrow"></i>
        <i class="mdi mdi-account menu-icon"></i>
      </a>
      <div class="collapse <?= $activeCommon ? 'show' : '' ?>" id="common" data-bs-parent="#sidebar-accordion">
        <ul class="nav flex-column sub-menu">
          <li class="nav-item">
            <a href="<?= base_url('backdesk/menu/index') ?>" class="nav-link <?= $activeCommon ? 'active' : '' ?>">Menu & Submenu</a>
          </li>
          <li class="nav-item">
            <a href="<?= base_url('backdesk/home/basic-details') ?>" class="nav-link <?= $activeCommon ? 'active' : '' ?>">Basic Details</a>
          </li>
        </ul>
      </div>
    </li>

    
    <!-- Home -->
    <li class="nav-item">
      <a class="nav-link <?= $activeHome ? 'active' : '' ?>" data-bs-toggle="collapse" href="#home" aria-expanded="<?= $activeHome ? 'true' : 'false' ?>" aria-controls="home">
        <span class="menu-title">Home</span>
        <i class="menu-arrow"></i>
        <i class="mdi mdi-account menu-icon"></i>
      </a>
      <div class="collapse <?= $activeHome ? 'show' : '' ?>" id="home" data-bs-parent="#sidebar-accordion">
        <ul class="nav flex-column sub-menu">
          <li class="nav-item"><a href="<?= base_url('backdesk/home-services/index') ?>" class="nav-link <?= ($current_controller === 'home-services') ? 'active' : '' ?>">Home Services</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/home-academic-programs/index') ?>" class="nav-link <?= ($current_controller === 'home-academic-programs') ? 'active' : '' ?>">Home Academic Programs</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/home-tender-notices/index') ?>" class="nav-link <?= ($current_controller === 'home-tender-notices') ? 'active' : '' ?>">Home Tender Notices</a></li>
        </ul>
      </div>
    </li>

    <!-- Departments -->
    <li class="nav-item">
      <a class="nav-link <?= $activeDepartments ? 'active' : '' ?>" data-bs-toggle="collapse" href="#module-author" aria-expanded="<?= $activeDepartments ? 'true' : 'false' ?>" aria-controls="module-author">
        <span class="menu-title">Departments</span>
        <i class="menu-arrow"></i>
        <i class="mdi mdi-account menu-icon"></i>
      </a>
      <div class="collapse <?= $activeDepartments ? 'show' : '' ?>" id="module-author" data-bs-parent="#sidebar-accordion">
        <ul class="nav flex-column sub-menu">
          <li class="nav-item"><a href="<?= base_url('backdesk/departments/index') ?>" class="nav-link <?= ($activeDepartments && $current_method === 'index') ? 'active' : '' ?>">Departments</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/departments/faculty-details') ?>" class="nav-link <?= ($activeDepartments && $current_method === 'faculty-details') ? 'active' : '' ?>">Faculty Details</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/departments/residents-details') ?>" class="nav-link <?= ($activeDepartments && $current_method === 'residents-details') ? 'active' : '' ?>">Residents Details</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/departments/gallery-details') ?>" class="nav-link <?= ($activeDepartments && $current_method === 'gallery-details') ? 'active' : '' ?>">Gallery</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/departments/posts') ?>" class="nav-link <?= ($activeDepartments && $current_method === 'posts') ? 'active' : '' ?>">Posts</a></li>
        </ul>
      </div>
    </li>

    <!-- Courses (single link) -->
    <li class="nav-item">
      <a class="nav-link <?= ($current_controller === 'courses') ? 'active' : '' ?>" href="<?= base_url('backdesk/courses') ?>">
        <span class="menu-title">Courses</span>
        <i class="mdi mdi-home menu-icon"></i>
      </a>
    </li>

    <!-- Library -->
    <li class="nav-item">
      <a class="nav-link <?= $activeLibrary ? 'active' : '' ?>" data-bs-toggle="collapse" href="#library" aria-expanded="<?= $activeLibrary ? 'true' : 'false' ?>" aria-controls="library">
        <span class="menu-title">Library</span>
        <i class="menu-arrow"></i>
        <i class="mdi mdi-account menu-icon"></i>
      </a>
      <div class="collapse <?= $activeLibrary ? 'show' : '' ?>" id="library" data-bs-parent="#sidebar-accordion">
        <ul class="nav flex-column sub-menu">
          <li class="nav-item"><a href="<?= base_url('backdesk/library/index') ?>" class="nav-link <?= ($activeLibrary && $current_method === 'index') ? 'active' : '' ?>">Library Details</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/library/collection') ?>" class="nav-link <?= ($activeLibrary && $current_method === 'collection') ? 'active' : '' ?>">Library Collection</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/library/team') ?>" class="nav-link <?= ($activeLibrary && $current_method === 'team') ? 'active' : '' ?>">Library Team</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/library/gallery') ?>" class="nav-link <?= ($activeLibrary && $current_method === 'gallery') ? 'active' : '' ?>">Library Gallery</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/library/requisition-form') ?>" class="nav-link <?= ($activeLibrary && $current_method === 'requisition-form') ? 'active' : '' ?>">Requisition Form</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/library/membership-form') ?>" class="nav-link <?= ($activeLibrary && $current_method === 'membership-form') ? 'active' : '' ?>">Membership Form</a></li>
        </ul>
      </div>
    </li>

    <!-- Interpages -->
    <li class="nav-item">
      <a class="nav-link <?= $activeInterpages ? 'active' : '' ?>" data-bs-toggle="collapse" href="#interpages" aria-expanded="<?= $activeInterpages ? 'true' : 'false' ?>" aria-controls="interpages">
        <span class="menu-title">Interpages</span>
        <i class="menu-arrow"></i>
        <i class="mdi mdi-account menu-icon"></i>
      </a>
      <div class="collapse <?= $activeInterpages ? 'show' : '' ?>" id="interpages" data-bs-parent="#sidebar-accordion">
        <ul class="nav flex-column sub-menu">
          <li class="nav-item"><a href="<?= base_url('backdesk/page-contents/index') ?>" class="nav-link <?= ($current_controller === 'page-contents') ? 'active' : '' ?>">Pages</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/page-media/index') ?>" class="nav-link <?= ($current_controller === 'page-media') ? 'active' : '' ?>">Media</a></li>
        </ul>
      </div>
    </li>

    <!-- Contacts -->
    <li class="nav-item">
      <a class="nav-link <?= $activeContacts ? 'active' : '' ?>" data-bs-toggle="collapse" href="#contacts" aria-expanded="<?= $activeContacts ? 'true' : 'false' ?>" aria-controls="contacts">
        <span class="menu-title">Contacts</span>
        <i class="menu-arrow"></i>
        <i class="mdi mdi-account menu-icon"></i>
      </a>
      <div class="collapse <?= $activeContacts ? 'show' : '' ?>" id="contacts" data-bs-parent="#sidebar-accordion">
        <ul class="nav flex-column sub-menu">
          <li class="nav-item"><a href="<?= base_url('backdesk/contacts/enquiry-form') ?>" class="nav-link <?= ($activeContacts && $current_method === 'enquiry-form') ? 'active' : '' ?>">Enquiry Form</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/contacts/feedback-form') ?>" class="nav-link <?= ($activeContacts && $current_method === 'feedback-form') ? 'active' : '' ?>">Feedback Form</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/contacts/emergency-contacts/index') ?>" class="nav-link <?= ($activeContacts && $current_method === 'emergency-contacts') ? 'active' : '' ?>">Emergency Contacts</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/contacts/key-personnel/index') ?>" class="nav-link <?= ($activeContacts && $current_method === 'key-personnel') ? 'active' : '' ?>">Key Personnel</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/contacts/administrative-offices/index') ?>" class="nav-link <?= ($activeContacts && $current_method === 'administrative-offices') ? 'active' : '' ?>">Administrative Offices</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/contacts/patient-services/index') ?>" class="nav-link <?= ($activeContacts && $current_method === 'patient-services') ? 'active' : '' ?>">Patient Services</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/contacts/office-hours/index') ?>" class="nav-link <?= ($activeContacts && $current_method === 'office-hours') ? 'active' : '' ?>">Office Hours</a></li>
          <li class="nav-item"><a href="<?= base_url('backdesk/contacts/campus-locations/index') ?>" class="nav-link <?= ($activeContacts && $current_method === 'campus-locations') ? 'active' : '' ?>">Campus Locations</a></li>
        </ul>
      </div>
    </li>

   

  </ul>
</nav>
<!-- Sidebar End -->
