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

// Cek apakah user sudah login dan role-nya sekretaris
if (!isset($_SESSION['user_id']) || !isset($_SESSION['role']) || $_SESSION['role'] != 'sekretaris') {
    // Redirect ke halaman login jika belum login atau bukan sekretaris
    setFlash('login_required', 'Anda harus login sebagai sekretaris 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' : '';
    }
}

// Hitung jumlah pesan kontak yang belum dibaca
$db = dbConnect();
$db->query("SELECT COUNT(*) as count FROM kontak WHERE is_read = 0");
$unread_count = $db->single()->count ?? 0;
?>

<!-- Sidebar Sekretaris -->
<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 ?>/sekretaris/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', 'kampanye') ?>" href="<?= SITE_URL ?>/sekretaris/kampanye/index.php">
                    <i class="fas fa-hand-holding-heart me-2"></i>
                    Kampanye
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link <?= isActive('index.php', 'berita') ?>" href="<?= SITE_URL ?>/sekretaris/berita/index.php">
                    <i class="fas fa-newspaper me-2"></i>
                    Berita Kegiatan
                </a>
            </li>
            
            <li class="nav-item">
                <a class="nav-link <?= isActive('index.php', 'profil') ?>" href="<?= SITE_URL ?>/sekretaris/profil/index.php">
                    <i class="fas fa-user-circle me-2"></i>
                    Profil Saya
                </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>
        
        <h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
            <span>Pintasan</span>
        </h6>
        <ul class="nav flex-column mb-2">
            <li class="nav-item">
                <a class="nav-link" href="<?= SITE_URL ?>" target="_blank">
                    <i class="fas fa-external-link-alt me-2"></i>
                    Lihat Website
                </a>
            </li>
        </ul>
    </div>
</nav>