<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}
$user = $_SESSION['username'] ?? null;
$role = $_SESSION['role'] ?? null;
$root_path = '/ooh_project/index.php';
?>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-4 fixed-top shadow" style="z-index:1040;margin-bottom:2px;">
  <div class="container-fluid flex-wrap">
    <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 flex-grow-1" id="mainNavbar">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item"><a class="nav-link" href="<?= $root_path ?>">Home</a></li>
        <?php if ($role === 'admin'): ?>
          <li class="nav-item"><a class="nav-link" href="<?= $root_path ?>?page=update_table">Update DB</a></li>
        <li class="nav-item"><a class="nav-link" href="<?= $root_path ?>?page=strategic_planning">Strategic Planning</a></li>
        <?php endif; ?>
        <?php if ($role === 'admin' || $role === 'staff'): ?>
        <li class="nav-item"><a class="nav-link" href="<?= $root_path ?>?page=competitor_review">Competitor Review</a></li>
        <li class="nav-item"><a class="nav-link" href="<?= $root_path ?>?page=site_evaluation">Site Evaluation</a></li>
        <?php endif; ?>
        <li class="nav-item"><a class="nav-link" href="<?= $root_path ?>?page=update_database">Market Overview</a></li>
      </ul>
      <div class="d-flex flex-column flex-lg-row align-items-center ms-lg-auto mt-2 mt-lg-0">
        <?php if (!$user): ?>
          <a class="btn btn-outline-light me-2 mb-2 mb-lg-0" href="<?= $root_path ?>?page=login">Login</a>
          <a class="btn btn-outline-light mb-2 mb-lg-0" href="<?= $root_path ?>?page=register">Register</a>
        <?php else: ?>
          <span class="navbar-text text-light me-2 mb-2 mb-lg-0 text-center w-100 w-lg-auto" style="white-space:nowrap;">Hello, <?= htmlspecialchars($user) ?>!</span>
          <a class="btn btn-outline-danger mb-2 mb-lg-0" href="<?= $root_path ?>?page=logout">Logout</a>
        <?php endif; ?>
      </div>
    </div>
  </div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<style>
body {
    padding-top: 70px; /* adjust if your navbar is taller */
}
</style>