<header>

{% set route_locale = app.request.attributes.get("_route") %}

<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
  <div class="container-fluid">
    <a class="navbar-brand" href="{{path('accueil')}}"><i class="fa-solid fa-book-atlas"></i></a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarColor01">
      <ul class="navbar-nav me-auto">
        <li class="nav-item">
          <a href="{{path('accueil')}}" class="nav-link
            {{ route_locale == "accueil" ? " active" : "" }}">
            Accueil
            <span class="visually-hidden">(current)</span>
          </a>
        </li>
        <li class="nav-item">
          <a href="{{path('listelivres')}}" class="nav-link
            {{ route_locale == "listelivres" ? " active" : "" }}">
            Livres
          </a>
        </li>

        {%- if is_granted('ROLE_USER') -%}

        {%- else -%}
          <li class="nav-item">
            <a href="{{path('connexion')}}" class="nav-link
              {{ route_locale == "connexion" ? " active" : "" }}">
              Se connecter
            </a>
          </li>
          <li class="nav-item">
            <a href="{{path('inscription')}}" class="nav-link
              {{ route_locale == "inscription" ? " active" : "" }}">
              S'inscrire
            </a>
          </li>
        {%- endif -%}

      </ul>
      
      {%- if (route_locale == "listelivres") -%}
        <form class="d-flex" method="post" action="{{ path('listelivres') }}">
          <input class="form-control me-sm-2" type="text" name="inputrecherche" placeholder="Rechercher">
          <button class="btnrecherchenav btn btn-secondary my-2 my-sm-0" type="submit">Rechercher</button>
        </form>
      {%- else -%}
        <div class="dropdown">
        <a href="{{ path('profile') }}" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">

        {%- if is_granted('ROLE_USER') -%}
          <a href="{{ path('profile') }}" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
          <img src="{{ asset('uploads/imgprofile/' ~ app.user.image) }}" width="50" height="50" class="rounded-circle me-2">
          <strong>{{ app.user.prenom }}</strong>
          <ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
            <li><a class="dropdown-item" href="{{path('parametres')}}">Paramètres</a></li>
            <li><a class="dropdown-item" href="{{path('profile')}}">Mon profil</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="{{path('logout')}}">Se déconnecter</a></li>
          </ul>
        {%- else -%}
          <a href="{{ path('profile') }}" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
          <i class="fa-solid fa-user" width="50" height="50" class="rounded-circle me-2"></i>
          <strong>Utilisateur</strong>
        
          <ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
            <li><a class="dropdown-item" href="{{path('connexion')}}">Se connecter</a></li>
            <li><a class="dropdown-item" href="{{path('inscription')}}">S'inscrire</a></li>
          </ul>
        {%- endif -%}

        </div>
      {%- endif -%}

    </div>
  </div>
</nav>

</header>