<div class="app-sidebar">
     <!-- Sidebar Logo -->
     <div class="logo-box">
          <a href="{{ route('dashboard.home') }}" class="logo-dark">
               <img src="/images/dputr-kab-bandung.png" class="logo-sm" alt="logo sm">
               <img src="/images/dputr-kab-bandung.png" class="logo-lg" alt="logo dark">
          </a>

          <a href="{{ route('dashboard.home') }}" class="logo-light">
               <img src="/images/dputr-kab-bandung.png" class="logo-sm" alt="logo sm">
               <img src="/images/dputr-kab-bandung.png" class="logo-lg" alt="logo light">
          </a>
     </div>

     <div class="scrollbar" data-simplebar>
          <ul class="navbar-nav" id="navbar-nav">
          <li class="menu-title">Menu</li>

          @php
          function renderMenu($menus) {
               foreach ($menus as $menu) {
                    $collapseId = "sidebar-" . $menu->id;
                    $hasChildren = $menu->children->count() > 0;

                    // Pastikan route tersedia dan boleh ditampilkan
                    $menuUrl = '#';
                    if ($menu->url) {
                         if (Route::has($menu->url)) {
                              $menuUrl = route($menu->url, ['menu_id' => $menu->id]);
                         } else {
                              $menuUrl = $menu->url . '?menu_id=' . $menu->id;
                         }
                    }

                    echo '<li class="nav-item ' . ($hasChildren ? 'has-children' : '') . '">';
                    echo '<a class="nav-link ' . ($hasChildren ? 'menu-arrow' : '') . '" 
                              href="' . ($hasChildren ? "#$collapseId" : $menuUrl) . '" 
                              ' . ($hasChildren ? 'data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="' . $collapseId . '"' : '') . '>';
                    
                    // Tampilkan ikon hanya jika tersedia
                    if (!empty($menu->icon)) {
                         echo '<span class="nav-icon">
                                   <iconify-icon icon="' . $menu->icon . '"></iconify-icon>
                              </span>';
                    }

                    echo '<span class="nav-text">' . $menu->name . '</span>';
                    echo '</a>';

                    if ($hasChildren) {
                         echo '<div class="collapse" id="' . $collapseId . '">
                                   <ul class="nav sub-navbar-nav">';
                         renderMenu($menu->children);
                         echo '</ul></div>';
                    }

                    echo '</li>';
               }
          }
          @endphp

          @php renderMenu($menus); @endphp
          </ul>
     </div>
</div>

<!-- Efek Bintang -->
<div class="animated-stars">
     @for ($i = 0; $i < 20; $i++)
          <div class="shooting-star"></div>
     @endfor
     @for ($i = 0; $i < 20; $i++)
          <div class="shooting-star"></div>
     @endfor
</div>