<?php
declare(strict_types=1);
/**
 * gov-portal-strip 가로 MY MENU (활성 대메뉴 하위 소메뉴 칩)
 *
 * @var list<array> $govNavItems
 * @var int $govActiveParentIdx
 * @var string $govActiveChildHref
 */
$activeParent = $govNavItems[$govActiveParentIdx] ?? $govNavItems[0] ?? null;
if ($activeParent === null) {
    return;
}
$children = $activeParent['children'] ?? [];
if ($children === []) {
    return;
}
$activeChildHref = strtolower(ltrim((string) ($govActiveChildHref ?? ''), '/'));
$sectionTitle = (string) ($activeParent['name'] ?? 'MY MENU');
?>
<nav class="strip-my-menu" aria-label="<?= esc($sectionTitle) ?> 하위 메뉴">
  <span class="strip-my-menu-title">MY MENU · <?= esc($sectionTitle) ?></span>
  <div class="strip-my-menu-chips">
    <?php foreach ($children as $ci => $child): ?>
    <?php if (($child['href'] ?? '') === ''): ?>
    <span class="menu-sub" style="opacity:.55;font-size:.75rem;padding:.35rem .5rem;"><?= esc($child['name']) ?></span>
    <?php else: ?>
    <?php
      $childHref = strtolower(ltrim((string) $child['href'], '/'));
      $isActive = $activeChildHref !== ''
          ? ($childHref === $activeChildHref)
          : ($ci === 0);
    ?>
    <a href="<?= esc($child['url']) ?>" class="<?= $isActive ? 'active' : '' ?>">
      <span class="menu-ico"><?= $isActive ? '×' : '+' ?></span>
      <?= esc($child['name']) ?>
    </a>
    <?php endif; ?>
    <?php endforeach; ?>
  </div>
</nav>
