<nav class="sidebar">
    <div class="sidebar-header">
        <a href="#" id="brand" class="sidebar-brand">
            <span id="brandName" style="font-size: 18px; font-weight: bold;"></span>
        </a>
        <div class=" sidebar-toggler not-active">
            <span></span>
            <span></span>
            <span></span>
        </div>
    </div>
    <div class="sidebar-body">
        <ul class="nav">
            <li class="nav-item nav-category">Main</li>
            <li class="nav-item">
                <a href="<?= base_url('Home/index') ?>" class="nav-link">
                    <i class="link-icon" data-feather="home"></i>
                    <span class="link-title">Dashboard</span>
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-bs-toggle="collapse" href="#masterdata" role="button" aria-expanded="false"
                    aria-controls="masterdata">
                    <i class="link-icon" data-feather="hard-drive"></i>
                    <span class="link-title">Master Data </span>
                    <i class="link-arrow" data-feather="chevron-down"></i>
                </a>
                <div class="collapse" id="masterdata">
                    <ul class="nav sub-menu">

                        <?php if (session()->get('role') === 'admin') : ?>

                            <li class="nav-item">
                                <a href="<?= base_url('jeniscuti'); ?>" class="nav-link">Data Jenis Cuti </a>
                            </li>
                            <li class="nav-item">
                                <a href="<?= base_url('jabatan'); ?>" class="nav-link">Data Jabatan</a>
                            </li>
                            <li class="nav-item">
                                <a href="<?= base_url('UnitKerja'); ?>" class="nav-link">Data Unit Kerja</a>
                            </li>
                        <?php endif; ?>

                        <li class="nav-item">
                            <a href="<?= base_url('users'); ?>" class="nav-link">Data User </a>
                        </li>


                    </ul>
                </div>
            </li>

            <li class="nav-item">
                <a href="<?= base_url('PengajuanCuti') ?>" class="nav-link">
                    <i class="link-icon" data-feather="database"></i>
                    <span class="link-title">Ajukan Cuti</span>
                </a>
            </li>

            <li class="nav-item">
                <a href="<?= base_url('Perizinan') ?>" class="nav-link">
                    <i class="link-icon" data-feather="award"></i>
                    <span class="link-title">Perizinan</span>
                </a>
            </li>

            <?php if (session()->get('role') === 'supervisor'): ?>
                <li class="nav-item">
                    <a href="<?= base_url('PengajuanCuti/supervisor') ?>" class="nav-link">
                        <i class="link-icon" data-feather="user-check"></i>
                        <span class="link-title">Persetujuan Cuti (Supervisor)</span>
                    </a>
                </li>
            <?php elseif (session()->get('role') === 'manager'): ?>
                <li class="nav-item">
                    <a href="<?= base_url('PengajuanCuti/manager') ?>" class="nav-link">
                        <i class="link-icon" data-feather="user-check"></i>
                        <span class="link-title">Persetujuan Cuti (Manager)</span>
                    </a>
                </li>
            <?php endif; ?>



            <?php if (session()->get('role') === 'admin') : ?>

                <li class="nav-item">
                    <a class="nav-link" data-bs-toggle="collapse" href="#laporan" role="button" aria-expanded="false"
                        aria-controls="laporan">
                        <i class="link-icon" data-feather="hard-drive"></i>
                        <span class="link-title">Laporan</span>
                        <i class="link-arrow" data-feather="chevron-down"></i>
                    </a>
                    <div class="collapse" id="laporan">
                        <ul class="nav sub-menu">
                            <li class="nav-item">
                                <a href="<?= base_url('laporan/pengajuancuti'); ?>" class="nav-link">Laporan Pengajuan Cuti </a>
                            </li>

                        </ul>
                    </div>
                </li>

                <li class="nav-item">
                    <a class="nav-link" data-bs-toggle="collapse" href="#settings" role="button" aria-expanded="false"
                        aria-controls="settings">
                        <i class="link-icon" data-feather="settings"></i>
                        <span class="link-title">Settings </span>
                        <i class="link-arrow" data-feather="chevron-down"></i>
                    </a>
                    <div class="collapse" id="settings">
                        <ul class="nav sub-menu">
                            <li class="nav-item">
                                <a href="<?= base_url('/Settings') ?>" class="nav-link">Data Settings</a>
                            </li>
                        </ul>
                    </div>
                </li>

            <?php endif; ?>


        </ul>
    </div>
</nav>

<script>
    $(document).ready(function() {
        $.ajax({
            url: "<?= base_url('/settings/getSettings') ?>", // tanpa level
            type: "GET",
            dataType: "json",
            success: function(response) {
                if (response.success && response.settings && response.settings.nama_aplikasi) {
                    // Update nama_aplikasi ke brand
                    $('#brandName').text(response.settings.nama_aplikasi);
                } else {
                    console.error("Pengaturan tidak ditemukan!");
                }
            },
            error: function() {
                console.error("Gagal mengambil data settings!");
            }
        });
    });
</script>