<?php
/**
 * partials/mobile_nav.php
 *
 * Navigasi cepat (bottom nav) untuk tampilan mobile.
 * Cara pakai: include file ini SEBELUM tag </body> di SETIAP halaman admin
 * (dashboard.php, data_komplain.php, input_komplain_admin.php, users.php, dll)
 *
 *   <?php include "../partials/mobile_nav.php"; ?>
 *   </body>
 *
 * Nav akan otomatis menandai menu yang aktif sesuai nama file halaman saat ini,
 * jadi tidak perlu diatur manual di tiap halaman.
 *
 * Menu yang tidak muat di bottom nav (Gaji, Akses User, Profil, Notifikasi,
 * Cetak PDF, Logout, dst) tetap bisa diakses lewat tombol "Lainnya" yang
 * membuka sidebar (data-widget="pushmenu" bawaan AdminLTE).
 */

$currentPage = basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$roleFolder = basename(dirname(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));

if (strpos($currentPage, 'cetak_') === 0) {
    return;
}

if ($roleFolder === 'admin') {
    $navItems = [
        [
            'href'  => 'dashboard.php',
            'icon'  => 'fa-house-chimney',
            'label' => 'Dashboard',
            'match' => ['dashboard.php', 'dashboard_full.php'],
        ],
        [
            'href'  => 'data_komplain.php',
            'icon'  => 'fa-table',
            'label' => 'Komplain',
            'match' => ['data_komplain.php', 'detail_komplain.php'],
        ],
        [
            'href'  => 'input_komplain_admin.php',
            'icon'  => 'fa-circle-plus',
            'label' => 'Input',
            'match' => ['input_komplain_admin.php', 'tambah_komplain.php'],
        ],
        [
            'href'  => '#',
            'icon'  => 'fa-bars',
            'label' => 'Lainnya',
            'match' => [],
            'widget' => 'pushmenu',
        ],
    ];
} elseif ($roleFolder === 'pelaksana') {
    $navItems = [
        [
            'href'  => 'dashboard.php',
            'icon'  => 'fa-house-chimney',
            'label' => 'Dashboard',
            'match' => ['dashboard.php'],
        ],
        [
            'href'  => 'data_komplain.php',
            'icon'  => 'fa-table',
            'label' => 'Komplain',
            'match' => ['data_komplain.php'],
        ],
        [
            'href'  => 'data_absensi.php',
            'icon'  => 'fa-user-clock',
            'label' => 'Absensi',
            'match' => ['data_absensi.php', 'absen.php'],
        ],
        [
            'href'  => '#',
            'icon'  => 'fa-bars',
            'label' => 'Lainnya',
            'match' => [],
            'widget' => 'pushmenu',
        ],
    ];
} elseif ($roleFolder === 'teknisi') {
    $navItems = [
        [
            'href'  => 'dashboard.php',
            'icon'  => 'fa-house-chimney',
            'label' => 'Dashboard',
            'match' => ['dashboard.php', 'teknisi.php'],
        ],
        [
            'href'  => 'data_komplain.php',
            'icon'  => 'fa-table',
            'label' => 'Komplain',
            'match' => ['data_komplain.php'],
        ],
        [
            'href'  => 'data_absensi.php',
            'icon'  => 'fa-user-clock',
            'label' => 'Absensi',
            'match' => ['data_absensi.php', 'absen.php'],
        ],
        [
            'href'  => '#',
            'icon'  => 'fa-bars',
            'label' => 'Lainnya',
            'match' => [],
            'widget' => 'pushmenu',
        ],
    ];
} else {
    $navItems = [
        [
            'href'  => 'dashboard.php',
            'icon'  => 'fa-house-chimney',
            'label' => 'Dashboard',
            'match' => ['dashboard.php'],
        ],
        [
            'href'  => 'data_absensi.php',
            'icon'  => 'fa-user-clock',
            'label' => 'Absensi',
            'match' => ['data_absensi.php', 'absen.php'],
        ],
        [
            'href'  => 'input_komplain_admin.php',
            'icon'  => 'fa-circle-plus',
            'label' => 'Input',
            'match' => ['input_komplain_admin.php'],
        ],
        [
            'href'  => '#',
            'icon'  => 'fa-bars',
            'label' => 'Lainnya',
            'match' => [],
            'widget' => 'pushmenu',
        ],
    ];
}
?>
<nav class="mobile-dashboard-nav" aria-label="Navigasi cepat">
    <?php foreach ($navItems as $item):
        $isActive = !empty($item['match']) && in_array($currentPage, $item['match'], true);
        $extraAttr = isset($item['widget']) ? ' data-widget="' . htmlspecialchars($item['widget']) . '"' : '';
    ?>
    <?php if (isset($item['widget'])): ?>
    <button type="button" class="<?= $isActive ? 'is-active' : '' ?>"<?= $extraAttr ?>>
        <span class="mobile-nav-icon"><i class="fas <?= $item['icon'] ?>"></i></span>
        <span class="mobile-nav-label"><?= $item['label'] ?></span>
    </button>
    <?php else: ?>
    <a href="<?= $item['href'] ?>" class="<?= $isActive ? 'is-active' : '' ?>"<?= $extraAttr ?>>
        <span class="mobile-nav-icon"><i class="fas <?= $item['icon'] ?>"></i></span>
        <span class="mobile-nav-label"><?= $item['label'] ?></span>
    </a>
    <?php endif; ?>
    <?php endforeach; ?>
</nav>
