<?php
// includes/header.php
require_once 'config.php';
require_once 'database.php';
require_once 'functions.php';


// Mulai session jika belum dimulai
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= isset($pageTitle) ? $pageTitle . ' - ' . SITE_NAME : SITE_NAME ?></title>
    
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    
    <!-- Font Awesome Icons -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    
    <!-- Custom CSS -->
    <link rel="stylesheet" href="<?= SITE_URL ?>/assets/css/style.css">
</head>
<body>
    <!-- Header/Navbar -->
    <header>
        <nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm sticky-top">
            <div class="container">
                <a class="navbar-brand" href="<?= SITE_URL ?>">
                    <img src="<?= SITE_URL ?>/assets/img/logo.jpg" alt="<?= SITE_NAME ?>" height="40">
                </a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav ms-auto">
                        <li class="nav-item">
                            <a class="nav-link <?= isset($activePage) && $activePage == 'home' ? 'active' : '' ?>" href="<?= SITE_URL ?>">Beranda</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link <?= isset($activePage) && $activePage == 'kampanye' ? 'active' : '' ?>" href="<?= SITE_URL ?>/pages/kampanye.php">Galang Dana</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link <?= isset($activePage) && $activePage == 'berita' ? 'active' : '' ?>" href="<?= SITE_URL ?>/pages/berita.php">Berita Kegiatan</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link <?= isset($activePage) && $activePage == 'tentang' ? 'active' : '' ?>" href="<?= SITE_URL ?>/pages/tentang-kami.php">Tentang Kami</a>
                        </li>
                        
                        <?php if (isLoggedIn()): ?>
    <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            <i class="fas fa-user-circle me-1"></i> <?= $_SESSION['nama_lengkap'] ?>
        </a>
        <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
            <?php if (isAdmin()): ?>
                <li><a class="dropdown-item" href="<?= SITE_URL ?>/admin/dashboard.php">Dashboard Admin</a></li>
                <li><hr class="dropdown-divider"></li>
            <?php elseif (isKetua()): ?>
                <li><a class="dropdown-item" href="<?= SITE_URL ?>/ketua/dashboard.php">Dashboard Ketua</a></li>
               
                <li><hr class="dropdown-divider"></li>
            <?php elseif (isSekretaris()): ?>
                <li><a class="dropdown-item" href="<?= SITE_URL ?>/sekretaris/dashboard.php">Dashboard Sekretaris</a></li>
             
                <li><hr class="dropdown-divider"></li>
            <?php elseif (isBendahara()): ?>
                <li><a class="dropdown-item" href="<?= SITE_URL ?>/bendahara/dashboard.php">Dashboard Bendahara</a></li>
               
                <li><hr class="dropdown-divider"></li>
            <?php elseif (isPengawas()): ?>
                <li><a class="dropdown-item" href="<?= SITE_URL ?>/pengawas/dashboard.php">Dashboard Pengawas</a></li>
                
                <li><hr class="dropdown-divider"></li>
            <?php else: ?>
                <li><a class="dropdown-item" href="<?= SITE_URL ?>/user/dashboard.php">Dashboard</a></li>
                <li><a class="dropdown-item" href="<?= SITE_URL ?>/user/donasi/index.php">Donasi Saya</a></li>
                <li><a class="dropdown-item" href="<?= SITE_URL ?>/user/profil/index.php">Profil</a></li>
                <li><hr class="dropdown-divider"></li>
            <?php endif; ?>
            <li><a class="dropdown-item" href="<?= SITE_URL ?>/auth/logout.php">Logout</a></li>
        </ul>
    </li>


                        <?php else: ?>
                            <li class="nav-item">
                                <a class="nav-link btn btn-outline-success btn-sm ms-2 px-3" href="<?= SITE_URL ?>/auth/login.php">Masuk</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link btn btn-success btn-sm ms-2 px-3 text-white" href="<?= SITE_URL ?>/auth/register.php">Daftar</a>
                            </li>
                        <?php endif; ?>
                    </ul>
                </div>
            </div>
        </nav>
    </header>
    
    <!-- Flash Messages -->
    <div class="container mt-3">
        <?php flash(); ?>
    </div>
    
    <!-- Main Content -->