{% load static %}
{% load simple_menu %}
{% 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 menu-compact dropdown-content mt-3 p-2 shadow bg-base-200 dark:bg-black rounded-box w-52 ">
        {% for item in menus.main %}
          {% if item.children %}
            <li tabindex="0">
              <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}}
                <svg class="fill-current" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z"/></svg>
              </a>
              <ul class="p-2 bg-base-200 rounded-md">
                {% 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>
            </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 p-0 text-sm rounded-lg md:gap-1">
      {% for item in menus.main %}
        {% if item.children %}
          <li tabindex="0">
            <a {% if item.boost %}hx-boost="true"{% else %}hx-boost="false"{% endif %} {% if item.url %}href="{{item.url}}"{% endif %} class="rounded-lg {% if item.selected %}active{% endif %}">
              {{item.title}}
              <svg class="fill-current" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"><path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z"/></svg>
            </a>
            <ul class="p-2 bg-base-200 gap-y-1 rounded-md">
              {% for child in item.children%}
                <li><a {% if item.boost %}hx-boost="true"{% else %}hx-boost="false"{% endif %} href="{{child.url}}" class="rounded-lg {% if child.selected %}active{% endif %}">{{child.title}}</a></li>
              {% endfor %}
            </ul>
          </li>
        {% else %}
          <li><a href="{{item.url}}" class="rounded-lg {% 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" %}
          </span>
        </label>
        <ul tabindex="0" class="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>
