<?php

require_once __DIR__ . '/../config/app.php';

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

$userRole = $_SESSION['role'] ?? '';
$userFullname = $_SESSION['fullname'] ?? '';

?>

<nav class="navbar navbar-expand-xl navbar-dark bg-primary shadow spchis-navbar">
    <div class="container-fluid spchis-navbar-container">

        <a class="navbar-brand spchis-brand" href="<?= BASE_URL ?>dashboard.php">
            <img
                src="<?= htmlspecialchars(SYSTEM_LOGO, ENT_QUOTES, 'UTF-8') ?>"
                class="spchis-logo"
                alt="<?= htmlspecialchars(SYSTEM_SHORT_NAME . ' logo', ENT_QUOTES, 'UTF-8') ?>"
            >

            <span class="spchis-brand-details">
                <span class="spchis-brand-short">
                    <?= htmlspecialchars(SYSTEM_SHORT_NAME, ENT_QUOTES, 'UTF-8') ?>
                </span>

                <span class="spchis-brand-province">
                    Sabaragamuwa Province
                </span>

                <span class="spchis-brand-system">
                    School Computer Hardware Inventory System
                </span>
            </span>
        </a>

        <button
            class="navbar-toggler"
            type="button"
            data-bs-toggle="collapse"
            data-bs-target="#mainNavbar"
            aria-controls="mainNavbar"
            aria-expanded="false"
            aria-label="Toggle navigation"
        >
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse spchis-navbar-collapse" id="mainNavbar">

            <ul class="navbar-nav spchis-main-menu">
                <li class="nav-item">
                    <a class="nav-link" href="<?= BASE_URL ?>dashboard.php">Dashboard</a>
                </li>

                <li class="nav-item">
                    <a class="nav-link" href="<?= BASE_URL ?>surveys/add_survey.php">New Survey</a>
                </li>

                <li class="nav-item">
                    <a class="nav-link" href="<?= BASE_URL ?>surveys/view_surveys.php">Surveys</a>
                </li>

                <?php if ($userRole === 'admin' || $userRole === 'zonal_director'): ?>
                    <li class="nav-item">
                        <a class="nav-link" href="<?= BASE_URL ?>admin/export_options.php">Reports</a>
                    </li>
                <?php endif; ?>

                <?php if ($userRole === 'admin'): ?>
                    <li class="nav-item">
                        <a class="nav-link" href="<?= BASE_URL ?>admin/admin_update.php">Update</a>
                    </li>

                    <li class="nav-item">
                        <a class="nav-link" href="<?= BASE_URL ?>admin/activity_logs.php">Activity Log</a>
                    </li>
                <?php endif; ?>
            </ul>

            <ul class="navbar-nav spchis-account-menu">
                <?php if ($userFullname !== ''): ?>
                    <li class="nav-item spchis-user-item">
                        <span class="nav-link spchis-user-text">
                            <span class="spchis-user-welcome">Welcome,</span>
                            <span class="spchis-user-name">
                                <?= htmlspecialchars($userFullname, ENT_QUOTES, 'UTF-8') ?>
                            </span>
                        </span>
                    </li>
                <?php endif; ?>

                <li class="nav-item spchis-logout-item">
                    <a class="nav-link" href="<?= BASE_URL ?>logout.php">Logout</a>
                </li>
            </ul>

        </div>
    </div>
</nav>
