<?php
// One nav component rendered two ways: fixed sidebar (>=992px) and an
// offcanvas drawer (<992px). Items are added here as the phase that builds
// their page lands, so the menu never contains a dead link.
$currentPage = $currentPage ?? '';
$navIsAdmin = current_user_is_admin();
?>
<nav class="sidebar" aria-label="Main">
  <div class="brand">
    <span class="brand-badge"><i class="bi bi-wallet2"></i></span>
    <span class="brand-name">月账 <span class="fw-normal text-secondary">· Monthly Ledger</span></span>
  </div>

  <div class="kicker mb-1" style="padding:0 .75rem;">Overview</div>
  <a class="side-link<?= $currentPage === 'dashboard' ? ' active' : '' ?>" href="index.php">
    <i class="bi bi-house"></i>Dashboard
  </a>
  <a class="side-link<?= $currentPage === 'expenses' ? ' active' : '' ?>" href="expenses.php">
    <i class="bi bi-list-ul"></i>All Expenses
  </a>
  <a class="side-link<?= $currentPage === 'reports' ? ' active' : '' ?>" href="reports.php">
    <i class="bi bi-graph-up"></i>Report
  </a>

  <div class="kicker mb-1 mt-3" style="padding:0 .75rem;">Planning</div>
  <a class="side-link<?= $currentPage === 'budgets' ? ' active' : '' ?>" href="budgets.php">
    <i class="bi bi-bullseye"></i>Budgets
  </a>
  <?php if ($navIsAdmin): ?>
  <a class="side-link<?= $currentPage === 'income' ? ' active' : '' ?>" href="income.php">
    <i class="bi bi-wallet2"></i>Income
  </a>
  <?php endif; ?>

  <div class="kicker mb-1 mt-3" style="padding:0 .75rem;">Settings</div>
  <?php if ($navIsAdmin): ?>
  <a class="side-link<?= $currentPage === 'manage' ? ' active' : '' ?>" href="manage.php">
    <i class="bi bi-tags"></i>Manage
  </a>
  <?php endif; ?>
  <a class="side-link<?= $currentPage === 'settings' ? ' active' : '' ?>" href="settings.php">
    <i class="bi bi-gear"></i>Settings
  </a>
  <?php if ($navIsAdmin): ?>
  <a class="side-link<?= $currentPage === 'log_dashboard' ? ' active' : '' ?>" href="log_dashboard.php">
    <i class="bi bi-shield-lock"></i>Log Dashboard
  </a>
  <?php endif; ?>

  <div class="side-footer">
    <a class="side-link" href="logout.php">
      <i class="bi bi-box-arrow-right"></i>Log out
    </a>
  </div>
</nav>

<div class="offcanvas offcanvas-start" tabindex="-1" id="menu" aria-labelledby="menuLabel" style="width:280px;">
  <div class="offcanvas-header pb-2">
    <div class="brand m-0 p-0" id="menuLabel">
      <span class="brand-badge"><i class="bi bi-wallet2"></i></span>
      <span class="brand-name">月账 <span class="fw-normal text-secondary">· Monthly Ledger</span></span>
    </div>
    <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
  </div>
  <div class="offcanvas-body d-flex flex-column pt-2">
    <div class="kicker mb-1" style="padding:0 .75rem;">Overview</div>
    <a class="side-link<?= $currentPage === 'dashboard' ? ' active' : '' ?>" href="index.php">
      <i class="bi bi-house"></i>Dashboard
    </a>
    <a class="side-link<?= $currentPage === 'expenses' ? ' active' : '' ?>" href="expenses.php">
      <i class="bi bi-list-ul"></i>All Expenses
    </a>
    <a class="side-link<?= $currentPage === 'reports' ? ' active' : '' ?>" href="reports.php">
      <i class="bi bi-graph-up"></i>Report
    </a>

    <div class="kicker mb-1 mt-3" style="padding:0 .75rem;">Planning</div>
    <a class="side-link<?= $currentPage === 'budgets' ? ' active' : '' ?>" href="budgets.php">
      <i class="bi bi-bullseye"></i>Budgets
    </a>
    <?php if ($navIsAdmin): ?>
    <a class="side-link<?= $currentPage === 'income' ? ' active' : '' ?>" href="income.php">
      <i class="bi bi-wallet2"></i>Income
    </a>
    <?php endif; ?>

    <div class="kicker mb-1 mt-3" style="padding:0 .75rem;">Settings</div>
    <?php if ($navIsAdmin): ?>
    <a class="side-link<?= $currentPage === 'manage' ? ' active' : '' ?>" href="manage.php">
      <i class="bi bi-tags"></i>Manage
    </a>
    <?php endif; ?>
    <a class="side-link<?= $currentPage === 'settings' ? ' active' : '' ?>" href="settings.php">
      <i class="bi bi-gear"></i>Settings
    </a>
    <?php if ($navIsAdmin): ?>
    <a class="side-link<?= $currentPage === 'log_dashboard' ? ' active' : '' ?>" href="log_dashboard.php">
      <i class="bi bi-shield-lock"></i>Log Dashboard
    </a>
    <?php endif; ?>

    <div class="side-footer">
      <a class="side-link" href="logout.php">
        <i class="bi bi-box-arrow-right"></i>Log out
      </a>
    </div>
  </div>
</div>
