<?php
// File: includes/sidebar-admin.php
// Sidebar admin untuk digunakan di semua halaman admin

// Cek apakah user sudah login dan role-nya admin
if (!isset($_SESSION['user_id']) || !isset($_SESSION['role']) || $_SESSION['role'] != 'admin') {
    // Redirect ke halaman login jika belum login atau bukan admin
    setFlash('login_required', 'Anda harus login sebagai admin untuk mengakses halaman ini', 'danger');
    header('Location: ' . SITE_URL . '/auth/login.php');
    exit;
}

// Tentukan halaman aktif
$current_page = basename($_SERVER['PHP_SELF']);
$current_folder = basename(dirname($_SERVER['PHP_SELF']));

function isActive($page, $folder = null) {
    global $current_page, $current_folder;
    
    if ($folder !== null) {
        return ($current_folder == $folder) ? 'active' : '';
    } else {
        return ($current_page == $page) ? 'active' : '';
    }
}
?>

<!-- Sidebar Admin -->
<nav id="sidebar" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
    <div class="position-sticky pt-3">
        <ul class="nav flex-column">
            <li class="nav-item">
                <a class="nav-link <?= isActive('dashboard.php') ?>" href="<?= SITE_URL ?>/admin/dashboard.php">
                    <i class="fas fa-tachometer-alt me-2"></i>
                    Dashboard
                </a>
            </li>
            
            <li class="nav-item">
                <a class="nav-link <?= isActive('index.php', 'users') ?>" href="<?= SITE_URL ?>/admin/users/index.php">
                    <i class="fas fa-users me-2"></i>
                    Users
                </a>
            </li>
            
            <li class="nav-item">
                <a class="nav-link" href="<?= SITE_URL ?>/auth/logout.php">
                    <i class="fas fa-sign-out-alt me-2"></i>
                    Logout
                </a>
            </li>
        </ul>
    </div>
</nav>