<?php

require_once "app/Config/NavigationMenu.php";

/**
 * @var array $menus
 */

$currentUrl = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$userRole = $_SESSION['user']["role"];

?>

<div class="list-group list-group-flush">

  <?php foreach ($menus as $menu): ?>

    <?php
    if (isset($menu['roles']) && !in_array($userRole, $menu['roles'])) {
      continue;
    } ?>

    <?php if ($menu['separator']): ?>

      <div class="list-group-item bg-light text-uppercase fw-semibold small text-secondary border-0 disabled">
        <?= $menu['title'] ?>
      </div>

    <?php else: ?>

      <?php
      $active = str_starts_with($currentUrl, $menu['url']);
      ?>

      <a
        href="<?= url($menu['url']) ?>"
        class="list-group-item list-group-item-action d-flex align-items-center gap-2 <?= $active ? 'active' : '' ?>">

        <i class="<?= $menu['icon'] ?>"></i>

        <span><?= $menu['title'] ?></span>

      </a>

    <?php endif; ?>

  <?php endforeach; ?>

</div>