<?php

if (!isset($_SESSION['user'])) {
    header("Location: /membership/login");
    exit;
}

$user = $_SESSION['user'];
$role = $user['role'] ?? 'Member';
$current = $_GET['url'] ?? 'dashboard';
?>

<div class="sidebar">

    <!-- LOGO -->
    <div class="logo">
        <h2>HITA</h2>
        <span>System</span>
    </div>

    <!-- USER INFO -->
    <div class="user-box">

        <?php if (!empty($user['foto'])): ?>
            <img 
                src="/membership/public/assets/uploads/<?= $user['foto'] ?>?v=<?= time() ?>" 
                class="sidebar-avatar"
            >
        <?php else: ?>
            <div class="avatar">
                <?= strtoupper(substr($user['nama'], 0, 1)) ?>
            </div>
        <?php endif; ?>

        <div class="user-info">
            <strong><?= htmlspecialchars($user['nama']) ?></strong>
            <small><?= $role ?></small>
        </div>

    </div>

    <!-- MENU -->
    <nav>

        <!-- DASHBOARD -->
        <a href="/membership/dashboard" class="<?= $current=='dashboard'?'active':'' ?>">
            Dashboard
        </a>

        <!-- ================= MEMBER ================= -->
        <?php if ($role == 'Member'): ?>

            <a href="/membership/iuran" class="<?= $current=='iuran'?'active':'' ?>">
                Iuran
            </a>

            <a href="/membership/event" class="<?= $current=='event'?'active':'' ?>">
                Event
            </a>

            <a href="/membership/members" class="<?= $current=='members'?'active':'' ?>">
                Member
            </a>

            <a href="/membership/jobs" class="<?= $current=='jobs'?'active':'' ?>">
                Lowongan
            </a>

        <?php endif; ?>

        <!-- ================= SEKRETARIS ================= -->
        <?php if ($role == 'Sekretaris'): ?>

            <a href="/membership/approve-member" class="<?= $current=='approve-member'?'active':'' ?>">
                Validasi Member
            </a>

            <a href="/membership/event-create" class="<?= $current=='event-create'?'active':'' ?>">
                Kelola Event
            </a>

            <a href="/membership/members" class="<?= $current=='members'?'active':'' ?>">
                Data Member
            </a>

            <a href="/membership/lowongan" class="<?= $current=='lowongan'?'active':'' ?>">
                Kelola Lowongan
            </a>

        <?php endif; ?>

        <!-- ================= BENDAHARA ================= -->
        <?php if ($role == 'Bendahara'): ?>

            <a href="/membership/iuran-list" class="<?= $current=='iuran-list'?'active':'' ?>">
                Data Iuran
            </a>

            <a href="/membership/kas-masuk" class="<?= $current=='kas-masuk'?'active':'' ?>">
                Kas Masuk
            </a>

            <a href="/membership/kas-keluar" class="<?= $current=='kas-keluar'?'active':'' ?>">
                Kas Keluar
            </a>

            <a href="/membership/laporan" class="<?= $current=='laporan'?'active':'' ?>">
                Laporan
            </a>
            
            <a href="/membership/iuran" class="<?= $current=='iuran'?'active':'' ?>">
                Iuran
            </a>

            <a href="/membership/members" class="<?= $current=='members'?'active':'' ?>">
                Member
            </a>

        <?php endif; ?>

        <!-- ================= SEMUA ROLE ================= -->
        <a href="/membership/profile" class="<?= $current=='profile'?'active':'' ?>">
            Profil
        </a>

    </nav>

    <!-- LOGOUT -->
    <a href="/membership/logout" class="logout">
        Logout
    </a>

</div>