<?php
$currentPage = basename($_SERVER['PHP_SELF'], '.php');
$storeName   = getSetting('store_name', 'Rewards System');

$nav = [
    ['href' => 'dashboard',            'icon' => 'speedometer2',   'label' => 'Dashboard',            'roles' => ['admin','cashier']],
    ['href' => 'card-generator',       'icon' => 'credit-card-2-front','label' => 'Card Generator',   'roles' => ['admin','cashier']],
    ['href' => 'bulk-print',           'icon' => 'printer',            'label' => 'Bulk Print Cards',  'roles' => ['admin','cashier']],
    ['href' => 'manage-cards',         'icon' => 'slash-circle',       'label' => 'Manage Cards',       'roles' => ['admin']],
    ['href' => 'member-registration',  'icon' => 'person-plus',    'label' => 'Member Registration',  'roles' => ['admin','cashier']],
    ['href' => 'purchase-scanner',     'icon' => 'bag-check',      'label' => 'Purchase Scanner',     'roles' => ['admin','cashier']],
    ['href' => 'redeem-points',        'icon' => 'gift',           'label' => 'Redeem Points',        'roles' => ['admin','cashier']],
    ['href' => 'members',              'icon' => 'people',         'label' => 'Members List',         'roles' => ['admin','cashier']],
    ['href' => 'reports',              'icon' => 'bar-chart-line', 'label' => 'Reports',              'roles' => ['admin','cashier']],
    ['href' => 'settings',             'icon' => 'gear',           'label' => 'Settings',             'roles' => ['admin']],
];
$role = $_SESSION['role'] ?? 'cashier';
?>
<nav id="sidebar" class="sidebar-nav d-flex flex-column">

  <div class="sidebar-brand px-3 py-3 d-flex align-items-center">
    <i class="bi bi-star-fill text-warning me-2 fs-5"></i>
    <span class="brand-text fw-bold"><?= e($storeName) ?></span>
  </div>

  <ul class="nav flex-column px-2 flex-grow-1">
    <?php foreach ($nav as $item):
      if (!in_array($role, $item['roles'])) continue;
      $active = ($currentPage === $item['href']);
    ?>
    <li class="nav-item">
      <a href="<?= BASE_URL ?>/<?= $item['href'] ?>.php"
         class="nav-link sidebar-link <?= $active ? 'active' : '' ?>">
        <i class="bi bi-<?= $item['icon'] ?> me-2"></i>
        <span class="link-text"><?= e($item['label']) ?></span>
      </a>
    </li>
    <?php endforeach; ?>
  </ul>

  <div class="px-3 py-2 sidebar-footer small text-muted">
    <i class="bi bi-info-circle me-1"></i>v<?= APP_VER ?>
  </div>
</nav>
