<?php
declare(strict_types=1);

$sidebarCategories = $sidebarCategories ?? [];
$sidebarCurrentBoardSlug = (string)($sidebarCurrentBoardSlug ?? '');
?>
<aside class="forum-sidebar">
  <div class="forum-sidebar__inner">
    <div class="forum-sidebar__head">
      <h2>Navigation</h2>
    </div>

    <div class="forum-sidebar__tree">
      <?php foreach ($sidebarCategories as $sidebarCategory): ?>
        <section class="forum-sidebar__group">
          <h3><?= htmlspecialchars((string)$sidebarCategory['title'], ENT_QUOTES) ?></h3>
          <ul>
            <?php foreach ($sidebarCategory['boards'] as $sidebarBoard): ?>
              <li>
                <a class="<?= $sidebarCurrentBoardSlug === (string)$sidebarBoard['slug'] ? 'is-active' : '' ?>" href="/community?board=<?= rawurlencode((string)$sidebarBoard['slug']) ?>">
                  <span><?= htmlspecialchars((string)$sidebarBoard['title'], ENT_QUOTES) ?></span>
                  <small><?= (int)($sidebarBoard['thread_count'] ?? 0) ?></small>
                </a>
              </li>
            <?php endforeach; ?>
          </ul>
        </section>
      <?php endforeach; ?>
    </div>
  </div>
</aside>
