<?php
require_once __DIR__ . "/../../app/config/session.php";
require_once __DIR__ . "/../../app/config/app.php";

$namaUser = getSession('pengurus_nama') ?? "Pengurus";
// Foto User
$pengurusFoto = getSession('pengurus_foto');
$root = dirname(__DIR__, 2);

$upload_path = $root . "/uploads/pengurus/";
$assets_path = $root . "/assets/img/pengurus/";

if ($pengurusFoto && file_exists($upload_path . $pengurusFoto)) {
    $fotoUser = base_url("/uploads/pengurus/" . $pengurusFoto);
} elseif ($pengurusFoto && file_exists($assets_path . $pengurusFoto)) {
    $fotoUser = base_url("/assets/img/pengurus/" . $pengurusFoto);
} else {
    $fotoUser = base_url("/assets/img/pengurus/user_default.png");
}

$currentPath = trim(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH), "/");

function isActive($keyword) { global $currentPath; return strpos($currentPath, $keyword) !== false ? "active" : ""; }
function isOpen($keyword) { global $currentPath; return strpos($currentPath, $keyword) !== false ? "open" : ""; }
?>

<aside class="sidebar" id="sidebar">
    <div class="sidebar-header">
        <img src="<?= base_url('/assets/img/src/logo-sidebar.png'); ?>" class="masjid-logo">
        <h2>Masjid</h2>
    </div>

    <div class="sidebar-profile">
        <img src="<?= $fotoUser ?>" class="user-photo">
        <div class="user-name"><?= htmlspecialchars($namaUser) ?></div>
    </div>

    <div class="sidebar-middle">
        <ul class="sidebar-menu">

            <!-- DASHBOARD -->
            <li>
                <a href="<?= base_url('/pages/web_dashboard/index.php'); ?>" 
                   class="ripple-container <?= isActive('web_dashboard') ?>">
                    <i class="fa fa-home"></i><span>Dashboard</span>
                </a>
            </li>

            <!-- JAMAAH -->
            <li class="sidebar-dropdown <?= isOpen('jamaah') ?>">
                <a href="#" class="dropdown-toggle-sidebar ripple-container">
                    <i class="fa-solid fa-users"></i><span>Jamaah</span>
                    <i class="fa fa-chevron-down arrow-icon ms-auto"></i>
                </a>
                <ul class="sidebar-submenu">

                    <li class="subuh-item"><a href="<?= base_url('/pages/jamaah/jamaah_subuh.php'); ?>"><i class="fa-solid fa-moon"></i>Subuh</a></li>
                    <li class="dzuhur-item"><a href="<?= base_url('/pages/jamaah/jamaah_dzuhur.php'); ?>"><i class="fa-solid fa-sun"></i>Dzuhur</a></li>
                    <li class="ashar-item"><a href="<?= base_url('/pages/jamaah/jamaah_ashar.php'); ?>"><i class="fa-regular fa-sun"></i>Ashar</a></li>
                    <li class="maghrib-item"><a href="<?= base_url('/pages/jamaah/jamaah_maghrib.php'); ?>"><i class="fa-solid fa-cloud-moon"></i>Maghrib</a></li>
                    <li class="isya-item"><a href="<?= base_url('/pages/jamaah/jamaah_isya.php'); ?>"><i class="fa-solid fa-star"></i>Isya</a></li>
                    <li class="diluar-item"><a href="<?= base_url('/pages/jamaah/jamaah_diluarwaktusholat.php'); ?>"><i class="fa-solid fa-clock"></i>Diluar Waktu</a></li>

                </ul>
            </li>

            <!-- SUMBER DAYA -->
            <li class="sidebar-dropdown <?= isOpen('log_sumberdaya') ?>">
                <a href="#" class="dropdown-toggle-sidebar ripple-container">
                    <i class="fa fa-cubes"></i><span>Sumber Daya</span>
                    <i class="fa fa-chevron-down arrow-icon ms-auto"></i>
                </a>
                <ul class="sidebar-submenu">

                    <li class="listrik-item"><a href="<?= base_url('/pages/log_sumberdaya/log_listrik.php'); ?>"><i class="fa fa-bolt"></i>Listrik</a></li>
                    <li class="air-item"><a href="<?= base_url('/pages/log_sumberdaya/log_air.php'); ?>"><i class="fa fa-tint"></i>Air</a></li>
                    <li class="suhu-item"><a href="<?= base_url('/pages/log_sumberdaya/log_suhu.php'); ?>"><i class="fa fa-temperature-half"></i>Suhu</a></li>
                    <li class="kelembapan-item"><a href="<?= base_url('/pages/log_sumberdaya/log_kelembapan.php'); ?>"><i class="fa fa-water"></i>Kelembapan</a></li>

                </ul>
            </li>

            <!-- KEUANGAN -->
            <li class="sidebar-dropdown <?= isOpen('keuangan') ?>">
                <a href="#" class="dropdown-toggle-sidebar ripple-container">
                    <i class="fa-solid fa-quran"></i><span>Keuangan</span>
                    <i class="fa fa-chevron-down arrow-icon ms-auto"></i>
                </a>
                <ul class="sidebar-submenu">

                    <li><a class="keuangan-masuk-item"href="<?= base_url('/pages/keuangan_masuk/index.php'); ?>"><i class="fa-solid fa-hand-holding-hand"></i>Pemasukan</a></li>
                    <li><a class="keuangan-keluar-item" href="<?= base_url('/pages/keuangan_keluar/index.php'); ?>"><i class="fa-solid fa-hand-holding-dollar"></i>Pengeluaran</a></li>

                </ul>
            </li>

            <!-- KEGIATAN -->
            <li class="sidebar-dropdown <?= isOpen('kegiatan') ?>">
                <a href="#" class="dropdown-toggle-sidebar ripple-container">
                    <i class="fa-solid fa-calendar-check"></i><span>Kegiatan</span>
                    <i class="fa fa-chevron-down arrow-icon ms-auto"></i>
                </a>
                <ul class="sidebar-submenu">

                    <li><a class="kegiatan-7hari-item" href="<?= base_url('/pages/kegiatan/kegiatan_7hari.php'); ?>"><i class="fa-solid fa-calendar-week"></i>Jadwal 7 Hari</a></li>
                    <li><a class="kegiatan-semua-item" href="<?= base_url('/pages/kegiatan/semua_kegiatan.php'); ?>"><i class="fa-solid fa-clipboard-list"></i>Semua Agenda</a></li>
                    <li><a class="kegiatan-tambah-item" href="<?= base_url('/pages/kegiatan/tambah_kegiatan.php'); ?>"><i class="fa-solid fa-plus"></i>Tambah Agenda</a></li>
                    <li><a class="kegiatan-riwayat-item" href="<?= base_url('/pages/kegiatan/riwayat_kegiatan.php'); ?>"><i class="fa-solid fa-clock-rotate-left"></i>Riwayat Agenda</a></li>

                </ul>
            </li>
            
            <!-- KRITIK DAN SARAN -->
            <li class="sidebar-dropdown <?= isOpen('kritik_saran') ?>">
                <a href="#" class="dropdown-toggle-sidebar ripple-container">
                    <i class="fa-solid fa-calendar-check"></i><span>Kritik & Saran</span>
                    <i class="fa fa-chevron-down arrow-icon ms-auto"></i>
                </a>
                <ul class="sidebar-submenu">

                    <li><a class="semua-kritik-saran" href="<?= base_url('/pages/kritik_saran/kritiksaran_admin.php'); ?>"><i class="fa-solid fa-calendar-week"></i>Semua Kritik & Saran</a></li>
                    <li><a class="kritik-saran-baru" href="<?= base_url('/pages/kritik_saran/kritiksaran_baru.php'); ?>"><i class="fa-solid fa-clipboard-list"></i>Kritik & Saran Baru</a></li>
                    <li><a class="kritik-saran-dibaca" href="<?= base_url('/pages/kritik_saran/kritiksaran_dibaca.php'); ?>"><i class="fa-solid fa-plus"></i>Kritik & Saran Dibaca</a></li>
                    <li><a class="riwayat-kritik-saran" href="<?= base_url('/pages/kritik_saran/kritiksaran_riwayat.php'); ?>"><i class="fa-solid fa-clock-rotate-left"></i>Riwayat Kritik & Saran</a></li>

                </ul>
            </li>

            <!-- LIVE -->
            <li>
                <a href="<?= base_url('/pages/web_monitoring/index.php'); ?>" 
                   class="ripple-container <?= isActive('web_monitoring') ?>">
                    <i class="fa fa-tv"></i><span>Monitoring Live</span>
                </a>
            </li>

        </ul>
    </div>

    <!-- LOGOUT -->
    <div class="sidebar-bottom">
        <a class="logout-btn ripple-container" href="<?= base_url('/app/auth/logout.php'); ?>">
            <i class="fa fa-right-from-bracket"></i><span>Logout</span>
        </a>
    </div>
</aside>
