<?php
declare(strict_types=1);
/** @var list<array> $govNavItems */
/** @var int $govActiveParentIdx */
/** @var string $govActiveChildHref */
$activeParent = $govNavItems[$govActiveParentIdx] ?? $govNavItems[0] ?? null;
$sidebarTitle = $activeParent['name'] ?? 'MY MENU';
$activeChildHref = strtolower(ltrim((string) ($govActiveChildHref ?? ''), '/'));
?>
<aside class="sidebar">
  <div class="my-menu-hd" id="portalSidebarTitle"><?= esc($sidebarTitle) ?></div>
  <ul class="my-menu-list" id="portalSidebarList">
    <?php if ($activeParent !== null): ?>
      <?php if (! empty($activeParent['hasChildren'])): ?>
        <?php foreach ($activeParent['children'] as $ci => $child): ?>
        <?php
          $childHref = strtolower(ltrim((string) ($child['href'] ?? ''), '/'));
          $isChildActive = $activeChildHref !== ''
              ? ($childHref === $activeChildHref)
              : ($ci === 0);
        ?>
        <li>
          <?php if ($child['href'] !== ''): ?>
          <a href="<?= esc($child['url']) ?>" class="<?= $isChildActive ? 'active' : '' ?>">
            <?= esc($child['name']) ?>
          </a>
          <?php else: ?>
          <span class="menu-sub" style="opacity:.65;cursor:default;">
            <?= esc($child['name']) ?>
          </span>
          <?php endif; ?>
        </li>
        <?php endforeach; ?>
      <?php elseif ($activeParent['href'] !== ''): ?>
        <li>
          <a href="<?= esc($activeParent['url']) ?>" class="active">
            <?= esc($activeParent['name']) ?>
          </a>
        </li>
      <?php endif; ?>
    <?php endif; ?>
  </ul>
  <div class="sidebar-blocks">
    <div class="sb-teal">
      <i class="fa-solid fa-mobile-screen"></i>
      모바일 앱(예정)<br/>지정판매소 판매·스캔 연동
    </div>
    <div class="sb-gray">
      <i class="fa-solid fa-repeat"></i> 통합 전환<br/>
      <a href="<?= base_url('admin/select-local-government') ?>" style="color:#fff;text-decoration:underline;">지자체 선택</a>
    </div>
    <div class="sb-links">
      <a href="<?= base_url('bag/manual') ?>">사용자 매뉴얼</a>
    </div>
  </div>
</aside>
