<nav class="navbar navbar-expand-lg bg-body-tertiary">
  <div class="container-fluid">
    <a class="navbar-brand" href="<%= root_path %>">
      <%= tag.i(class: "bi bi-universal-access") %>
      a11ydive
    </a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <% if @navbar_items %>
        <ul class="navbar-nav me-auto mb-2 mb-lg-0">
          <% @navbar_items.each do |navbar_item| %>
            <% dropdown = (navbar_item[:active] || @nav_path.to_s == navbar_item[:path].to_s) && @sidebar_items.any? %>
            <li class="nav-item<%= " dropdown" if dropdown %>">
              <% if navbar_item[:method].present? && navbar_item[:method] != :get %>
                <%= button_to(navbar_item[:path], method: navbar_item[:method], class: "nav-link#{" dropdown-toggle" if dropdown }") do %>
                  <% if navbar_item[:icon] %>
                    <span aria-hidden="true" class="bi-<%= navbar_item[:icon] %>"></span>
                  <% end %>
                  <%= navbar_item[:label] %>
                <% end %>
              <% else %>
                <div class="d-md-none">
                  <a class="nav-link <%= (navbar_item[:active] || @nav_path.to_s == navbar_item[:path].to_s) && "active#{"" if dropdown }" %>" <%= @nav_path.to_s == navbar_item[:path].to_s && "aria-current=\"page\"" %> 
                    href="<%= dropdown ? "#" : url_for(navbar_item[:path]) %>" <%= dropdown ? 'role="button" data-bs-toggle="dropdown" aria-expanded="false"' : "" %>>
                    <% if navbar_item[:icon] %>
                      <span aria-hidden="true" class="bi-<%= navbar_item[:icon] %>"></span>
                    <% end %>
                    <%= navbar_item[:label] %>
                  </a>
                  <% if dropdown %>
                    <ul class="">
                      <% @sidebar_items.each do |sidebar_item| %>
                        <li class="dropdown-item">
                          <a class="nav-link text-truncate <%= ((sidebar_item[:active] || @nav_path.to_s == sidebar_item[:path].to_s) && "active") || "" %>" <%= @nav_path.to_s == sidebar_item[:path].to_s && "aria-current=\"page\"" || "" %> href="<%= url_for(sidebar_item[:path]) %>">
                            <% if sidebar_item[:icon] %>
                              <span aria-hidden="true" class="bi-<%= sidebar_item[:icon] %>"></span>
                            <% end %>
                            <%= sidebar_item[:label] %>
                          </a>
                        </li>
                      <% end %>
                    </ul>
                  <% end %>
                </div>
                <div class="d-none d-md-block">
                  <a class="nav-link <%= (navbar_item[:active] || @nav_path.to_s == navbar_item[:path].to_s) && "active" || "" %>" <%= @nav_path.to_s == navbar_item[:path].to_s && "aria-current=\"page\"" || "" %> 
                    href="<%= url_for(navbar_item[:path]) %>">
                    <% if navbar_item[:icon] %>
                      <span aria-hidden="true" class="bi-<%= navbar_item[:icon] %>"></span>
                    <% end %>
                    <%= navbar_item[:label] %>
                  </a>
                </div>
              <% end %>
            </li>
          <% end %>
          <%# <li class="nav-item">
            <a class="nav-link" href="#">Link</a>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
              Dropdown
            </a>
            <ul class="dropdown-menu">
              <li><a class="dropdown-item" href="#">Action</a></li>
              <li><a class="dropdown-item" href="#">Another action</a></li>
              <li><hr class="dropdown-divider"></li>
              <li><a class="dropdown-item" href="#">Something else here</a></li>
            </ul>
          </li>
          <li class="nav-item">
            <a class="nav-link disabled" aria-disabled="true">Disabled</a>
          </li> %>
        </ul>
      <% else %>
        <div class="me-auto"></div>
      <% end %>
      <% if @search_url %>
        <form class="d-flex" role="search" action="<%= @search_url %>">
          <input class="form-control me-2" type="search" placeholder="<%= @search_placeholder || "..." %>" aria-label="Search">
          <button class="btn btn-outline-success" type="submit" name="<%= @search_name || "q" %>"><%= @search_placeholder || "Suchen" %></button>
        </form>
      <% end %>
      <ul class="navbar-nav flex-row flex-wrap ms-md-auto">
        <li class="nav-item">
          <button class="btn btn-link nav-link py-2 px-0 px-lg-2 d-flex align-items-center"
                  data-controller="theme-switcher"
                  data-action="theme-switcher#switch"
                  id="bd-theme"
                  type="button"
                  data-bs-display="static"
                  aria-label="Toggle theme (auto)">
            <i class="bi <%= cookies[:modeTheme] == "dark" ? "bi-moon-stars-fill" : "bi-sun-fill" %> my-1"></i>
          </button>
        </li>
      </ul>
    </div>
  </div>
</nav>
