<?php

/** @var \App\Assets $assets */
$assets->addInlineJs($this->fetch('partials/sidebar_menu.js'), 99);

/**
 * @var array $menu
 * @var string $active
 * @var \App\Http\Router $router
 */

$active ??= null;
?>
<ul class="navdrawer-nav">
    <?php
    foreach ($menu as $category_id => $category): ?>
        <li class="nav-item">
            <a class="nav-link <?=($category['class'] ?? '')?> <?php
            if ($active === $category_id): ?>active<?php
            endif; ?>"
               <?php
               if (empty($category['items'])): ?>href="<?=$category['url']?>" <?php
               else: ?>data-toggle="collapse" href="#sidebar-submenu-<?=$category_id?>"<?php
            endif; ?>
               <?php
               if ($category['external'] ?? false): ?>target="_blank"<?php
            endif; ?>
               <?php
               if (isset($category['confirm'])): ?>data-confirm-title="<?=$this->e($category['confirm'])?>"<?php
            endif; ?>
               <?php
               if (isset($category['title'])): ?>title="<?=$this->e($category['title'])?>"<?php
            endif; ?>>
                <i class="navdrawer-nav-icon material-icons" aria-hidden="true"><?=$category['icon']?></i>
                <?=$category['label']?>
                <?php
                if ($category['external'] ?? false): ?>
                    <i class="material-icons sm">open_in_new</i>
                <?php
                endif; ?>
            </a>
            <?php
            if (!empty($category['items'])): ?>
                <div class="collapse pb-2" id="sidebar-submenu-<?=$category_id?>">
                    <ul class="navdrawer-nav">
                        <?php
                        foreach ($category['items'] as $item_id => $item): ?>
                            <li class="nav-item">
                                <a class="nav-link pl-4 py-2 text-muted <?=($item['class'] ?? '')?>"
                                   href="<?=$item['url']?>"
                                   <?php
                                   if ($item['external'] ?? false): ?>target="_blank"<?php
                                endif; ?>
                                   <?php
                                   if (isset($item['confirm'])): ?>data-confirm-title="<?=$this->e(
                                       $item['confirm']
                                   )?>"<?php
                                endif; ?>
                                   <?php
                                   if (isset($item['title'])): ?>title="<?=$this->e($item['title'])?>"<?php
                                endif; ?>>
                                    <?=$item['label']?>
                                </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                </div>
            <?php endif; ?>
        </li>
    <?php endforeach; ?>
</ul>
