<?php
// File: header.php
// The header template for all secure admin pages. Includes sidebar and top navbar.

// Determine the active page to highlight the correct sidebar link
$current_page = basename($_SERVER['PHP_SELF']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo isset($page_title) ? htmlspecialchars($page_title) : 'Barangay Profiling System'; ?> - BRPMS</title>
    <!-- CACHE BUSTING FIX: Added a unique timestamp to the CSS link -->
    <link rel="stylesheet" href="css/style.css?v=<?php echo time(); ?>">
    <!-- Font Awesome for icons -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
</head>
<body data-theme="light"> <!-- Default theme -->
    <div class="wrapper">
        <!-- Sidebar -->
        <nav class="sidebar">
            <div class="sidebar-header">
                <h3>BRPMS</h3>
                <strong>Barangay San Fabian</strong>
            </div>

            <ul class="list-unstyled components">
                <li class="<?php echo ($current_page == 'dashboard.php') ? 'active' : ''; ?>">
                    <a href="dashboard.php">
                        <i class="fas fa-tachometer-alt"></i>
                        Dashboard
                    </a>
                </li>
                
                <li class="<?php echo ($current_page == 'residents.php') ? 'active' : ''; ?>">
                    <a href="residents.php">
                        <i class="fas fa-users"></i>
                        All Residents
                    </a>
                </li>

                <li class="<?php echo ($current_page == 'households.php' || $current_page == 'manage_members.php') ? 'active' : ''; ?>">
                    <a href="households.php">
                        <i class="fas fa-home"></i>
                        Households
                    </a>
                </li>
                <li class="<?php echo ($current_page == 'boarders.php') ? 'active' : ''; ?>">
                    <a href="boarders.php">
                        <i class="fas fa-user-friends"></i>
                        Boarders
                    </a>
                </li>
                <li class="<?php echo ($current_page == 'archived_records.php') ? 'active' : ''; ?>">
                    <a href="archived_records.php">
                        <i class="fas fa-archive"></i>
                        Archived Records
                    </a>
                </li>
                <li class="<?php echo ($current_page == 'reports.php') ? 'active' : ''; ?>">
                    <a href="reports.php">
                        <i class="fas fa-chart-bar"></i>
                        Reports
                    </a>
                </li>
                <?php if(isset($_SESSION['user_id']) && $_SESSION['user_id'] == 1): ?>
                <li class="<?php echo ($current_page == 'users.php') ? 'active' : ''; ?>">
                    <a href="users.php">
                        <i class="fas fa-user-cog"></i>
                        Users
                    </a>
                </li>
                <?php endif; ?>
            </ul>
        </nav>

        <!-- Page Content -->
        <div id="content">
            <nav class="navbar">
                <!-- Theme Switcher -->
                <div class="theme-switcher">
                    <button class="theme-btn" data-theme="light" title="Light Mode"><i class="fas fa-sun"></i></button>
                    <button class="theme-btn" data-theme="grey" title="Grey Mode"><i class="fas fa-moon"></i></button>
                    <button class="theme-btn" data-theme="dark" title="Dark Mode"><i class="fas fa-star"></i></button>
                </div>

                <div class="user-profile">
                     <?php
                        $profile_pic_path = 'uploads/' . ($_SESSION['profile_image'] ?? 'default.png');
                        if (!file_exists($profile_pic_path)) {
                            $profile_pic_path = 'uploads/default.png'; // Fallback
                        }
                     ?>
                     <img src="<?php echo $profile_pic_path; ?>" alt="Profile" class="profile-pic-nav">
                     <span>Welcome, <?php echo htmlspecialchars($_SESSION['name'] ?? 'Admin'); ?>!</span>
                     <a href="logout.php" class="logout-link" title="Logout"><i class="fas fa-sign-out-alt"></i></a>
                </div>
            </nav>
            
            <div class="container-fluid pt-3">
                <!-- Content injected below -->