<?php
/**
 * templates/sidebar.php — Left sidebar navigation
 * Menu items are shown/hidden based on current_user_role().
 *
 * Variables expected:
 *   $active_page  string  e.g. 'dashboard', 'agencies', 'users', 'learners',
 *                          'certificates', 'profile'
 */
$active_page = $active_page ?? '';
$is_super    = is_super_admin();
?>
<nav class="sidebar-wrapper sidebar-dark" id="sidebar-wrapper">
    <div class="simplebar-wrapper">
        <div class="sidebar-menu">

            <!-- Sidebar header / logo area -->
            <div class="sidebar-header">
                <a href="<?= base_url('pages/dashboard.php') ?>">
                    <img src="<?= base_url('assets/img/logo_white.png') ?>" alt="<?= e(APP_NAME) ?>" style="max-height:38px;">
                </a>
            </div>

            <div class="sidebar-content">
                <ul class="sidebar-menu-list list-unstyled">

                    <!-- Dashboard -->
                    <li class="sidebar-menu-item <?= active_if($active_page === 'dashboard') ?>">
                        <a href="<?= base_url('pages/dashboard.php') ?>" class="sidebar-menu-link">
                            <i class="menu-icon feather-home"></i>
                            <span class="menu-title">Dashboard</span>
                        </a>
                    </li>

                    <?php if ($is_super): ?>
                    <!-- ── Super Admin only ───────────────────── -->

                    <li class="sidebar-menu-header">
                        <span>Administration</span>
                    </li>

                    <!-- Agencies -->
                    <li class="sidebar-menu-item <?= active_if($active_page === 'agencies') ?>">
                        <a href="<?= base_url('pages/agencies.php') ?>" class="sidebar-menu-link">
                            <i class="menu-icon feather-briefcase"></i>
                            <span class="menu-title">Agencies</span>
                        </a>
                    </li>

                    <!-- Users / Admins -->
                    <li class="sidebar-menu-item <?= active_if($active_page === 'users') ?>">
                        <a href="<?= base_url('pages/users.php') ?>" class="sidebar-menu-link">
                            <i class="menu-icon feather-users"></i>
                            <span class="menu-title">Users &amp; Admins</span>
                        </a>
                    </li>

                    <?php endif; ?>

                    <!-- ── Both roles ─────────────────────────── -->

                    <li class="sidebar-menu-header">
                        <span>Training Records</span>
                    </li>

                    <!-- Learners -->
                    <li class="sidebar-menu-item <?= active_if($active_page === 'learners') ?>">
                        <a href="<?= base_url('pages/learners.php') ?>" class="sidebar-menu-link">
                            <i class="menu-icon feather-book-open"></i>
                            <span class="menu-title">Learners</span>
                        </a>
                    </li>

                    <!-- Certificates -->
                    <li class="sidebar-menu-item <?= active_if($active_page === 'certificates') ?>">
                        <a href="<?= base_url('pages/certificates.php') ?>" class="sidebar-menu-link">
                            <i class="menu-icon feather-award"></i>
                            <span class="menu-title">Certificates</span>
                        </a>
                    </li>

                    <!-- ── Account ────────────────────────────── -->

                    <li class="sidebar-menu-header">
                        <span>Account</span>
                    </li>

                    <!-- Profile -->
                    <li class="sidebar-menu-item <?= active_if($active_page === 'profile') ?>">
                        <a href="<?= base_url('pages/profile.php') ?>" class="sidebar-menu-link">
                            <i class="menu-icon feather-user"></i>
                            <span class="menu-title">My Profile</span>
                        </a>
                    </li>

                    <!-- Sign Out -->
                    <li class="sidebar-menu-item">
                        <a href="<?= base_url('logout.php') ?>" class="sidebar-menu-link text-danger">
                            <i class="menu-icon feather-log-out"></i>
                            <span class="menu-title">Sign Out</span>
                        </a>
                    </li>

                </ul>
            </div><!-- /.sidebar-content -->
        </div><!-- /.sidebar-menu -->
    </div>
</nav>
