{% load simple_menu static %}
{% generate_menu %}
<nav class="navbar bg-base-200 dark:bg-black font-medium shadow-md" hx-boost="true" >
  <div class="navbar-start">
    <div class="dropdown">
      {% comment %} Mobile menu {% endcomment %}
      <label tabindex="0" class="btn btn-ghost sm:hidden">
        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h8m-8 6h16" /></svg>
      </label>
      <ul tabindex="0" class="menu dropdown-content mt-3 z-[20] p-2 shadow bg-base-200 dark:bg-black rounded-box w-52">
        {% for item in menus.main %}
          {% if item.children %}
            <li tabindex="0">
              <details>
                <summary>
                  <a {% if item.boost %}hx-boost="true"{% else %}hx-boost="false"{% endif %} {% if item.url %}href="{{ item.url }}"{% endif %} class="justify-between {% if item.selected %}active{% endif %}">
                    {{ item.title }}
                  </a>
                </summary>
                <ul class="p-2 rounded-md z-[15]">
                  {% for child in item.children %}
                    <li><a {% if item.boost %}hx-boost="true"{% else %}hx-boost="false"{% endif %} href="{{ child.url }}" class="{% if child.selected %}active{% endif %}">{{ child.title }}{% if item.badge %}<span class="badge">{{ child.badge }}</span>
                    {% endif %}</a></li>
                  {% endfor %}
                </ul>
              </details>
            </li>
          {% else %}
            <li>
              <a href="{{ item.url }}" class="{% if item.selected %}active {% endif %}">{{ item.title }}</a>
            </li>
          {% endif %}
        {% endfor %}
      </ul>
    </div>
    <a class="btn btn-ghost" href="{% url 'incidents:dashboard' %}">
      <img class="h-11" height="44" src="{% static "img/logo-firefighter.png" %}" alt="{{ APP_DISPLAY_NAME }} logo"/>
    </a>
  </div>
  <div class="navbar-center hidden sm:flex">
    <ul class="menu menu-horizontal text-sm rounded-lg md:gap-1">
      {% for item in menus.main %}
        {% if item.children %}
          <li class="dropdown dropdown-hover dropdown-bottom ">
            <div tabindex="0" role="button" class="btn btn-ghost">
              <a {% if item.boost %}hx-boost="true"{% else %}hx-boost="false"{% endif %} {% if item.url %} href="{{ item.url }}"{% endif %} class="{% if item.selected %}{% endif %}">
                {{ item.title }}
              </a>
            </div>
            <ul tabindex="0" class="dropdown-content p-2 rounded-md z-[15] ml-0 p-2 shadow bg-base-200 dark:bg-black rounded-box w-auto">
              {% for child in item.children %}
                <li class="py-1">
                  <a {% if item.boost %}hx-boost="true"{% else %}hx-boost="false"{% endif %} href="{{ child.url }}"
                     class="whitespace-nowrap rounded-md {% if child.selected %}active{% endif %}">
                    {{ child.title }}
                  </a>
                </li>
              {% endfor %}
            </ul>
          </li>
        {% else %}
          <li><a href="{{ item.url }}" class="btn btn-ghost{% if item.selected %}active{% endif %}">{{ item.title }}</a></li>
        {% endif %}
      {% endfor %}
    </ul>
  </div>

  <div class="navbar-end ">
    <div class="dropdown dropdown-end">
      {% if user.is_authenticated %}
        <label tabindex="0" class="btn btn-ghost btn-circle avatar rounded-full">
          <span class="inline-flex w-10 h-10">
            {% component "avatar" user=user size="md" %}{% endcomponent %}
          </span>
        </label>
        <ul tabindex="0" class="z-[90] mt-3 p-2 shadow menu menu-compact dropdown-content bg-base-200 dark:bg-black rounded-box w-52">
          <div class="py-3 px-4 text-sm text-neutral-900 dark:text-white">
            <div>{{ user.full_name }}</div>
          </div>
          {% for item in menus.user %}
            <li>
              <a
                href="{{ item.url }}"
                {% if item.boost %}hx-boost="true"{% else %}hx-boost="false"{% endif %}
                class="justify-between">
                {{ item.title }}
                {% if item.badge %}
                  <span class="badge">{{ item.badge }}</span>
                {% endif %}
              </a>
            </li>
          {% endfor %}
        </ul>
        </div>
      {% else %}
        <a hx-boost="false" class="btn btn-primary" href="{% url "oidc_authentication" %}?next={% if request.GET.next is not None %}{{ request.GET.next|default:"/"|urlencode }}{% elif request.get_full_path %}{{ request.get_full_path|urlencode }}{% else %}{{ ""|urlencode }}{% endif %}&fail=/admin/login/">Login</a>
      {% endif %}
    </div>
  </nav>
