{% load i18n static %}
{% load wagtailcore_tags %}

{% slugurl "k-fet" as kfet_home_url %}

<nav class="navbar navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="{{ kfet_home_url }}">
        <img src="{% static 'kfet/img/logo3.png' %}">
      </a>
    </div>
    <ul class="nav navbar-nav">
      <li class="kfetopen dropdown">
        <ul class="base nav dropdown-toggle" data-toggle="dropdown">
          <li class="bullet"></li>
          {% if perms.kfet.is_team %}
          <li class="warning fade">
            <span class="glyphicon glyphicon-warning-sign"></span>
          </li>
          {% endif %}
        </ul>
        <div class="details dropdown-menu">
          La K-Fêt est
          <b><span class="status-text">
            <span class="glyphicon glyphicon-refresh spinning"></span>
          </span></b>.
          {% if perms.kfet.is_team %}
          <button class="btn btn-primary force-close-btn">&nbsp;</button>
          {% endif %}
        </div>
      </li>
      {% for item in menu_items %}
      {% if item.text == "Accueil" %}
      <li class="{{ item.active_class }} hidden-xs hidden-sm hidden-md">
        <a href="{{ item.href }}" title="Accueil">
          <span class="glyphicon glyphicon-home"></span>
        </a>
      </li>
      {% else %}
      <li class="{{ item.active_class }} hidden-xs hidden-sm hidden-md">
        <a href="{{ item.href }}">
          {{ item.text }}
        </a>
      </li>
      {% endif %}
      {% endfor %}
      <li class="dropdown visible-xs visible-sm visible-md nav-pages">
        <a href="#" data-toggle="dropdown" roles="button" aria-haspopup="true" aria-expanded="false" class="navbar-toggle">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </a>
        <ul class="dropdown-menu">
          {% for item in menu_items %}
          <li>
            <a href="{{ item.href }}">
              {{ item.text }}
            </a>
          </li>
          {% endfor %}
        </ul>
      </li>
    </ul>
    <ul class="nav navbar-nav navbar-right nav-app">
      {% if user.username == 'kfet_genericteam' %}
        {% trans "Session partagée" as shared_str %}
        {% include "kfet/nav_item.html" with text=shared_str glyphicon="sunglasses" %}
      {% elif user.is_authenticated and not user.profile.account_kfet %}
        {% include "kfet/nav_item.html" with class="disabled" href="#" glyphicon="user" text="Mon compte" %}
      {% elif user.profile.account_kfet.readable %}
        {% url "kfet.account.read" user.profile.account_kfet.trigramme as url_my_account %}
        {% include "kfet/nav_item.html" with href=url_my_account glyphicon="user" text="Mon compte" %}
      {% endif %}
      {% if perms.kfet.is_team %}
        {% include "kfet/nav_item.html" with url="kfet.kpsul" glyphicon="shopping-cart" text="K-Psul" %}
        {% include "kfet/nav_item.html" with url="kfet.transfers" glyphicon="transfer" text="Transferts" %}
        {% include "kfet/nav_item.html" with url="kfet.history" glyphicon="th-list" text="Historique" %}
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          <span class="glyphicon glyphicon-option-vertical"></span>
        </a>
        <ul class="dropdown-menu">
          <li class="divider"></li>
          <li><a href="{% url 'kfet.account' %}">Comptes</a></li>
          <li><a href="{% url 'kfet.checkout' %}">Caisses</a></li>
          <li class="divider"></li>
          <li><a href="{% url 'kfet.article' %}">Articles</a></li>
          <li><a href="{% url 'kfet.inventory' %}">Inventaires</a></li>
          <li><a href="{% url 'kfet.order' %}">Commandes</a></li>
          {% if user.username != 'kfet_genericteam' %}
          <li class="divider"></li>
          <li>
            <a href="#" data-url="{% url "kfet.login.generic" %}" onclick="submit_url(this)">
              {% trans "Ouvrir une session partagée" %}
            </a>
          </li>
          {% endif %}
          {% if perms.kfet.change_settings %}
          <li><a href="{% url 'kfet.settings' %}">Paramètres</a></li>
          {% endif %}
          <li class="divider"></li>
          <li>
            <a href="{% url "cof-logout" %}?next={{ kfet_home_url|urlencode }}">
              <span class="glyphicon glyphicon-log-out"></span><span>Déconnexion</span>
            </a>
          </li>
        </ul>
      </li>
      {% endif %}
      {% if user.is_authenticated and not perms.kfet.is_team %}
      <li>
        <a href="{% url "cof-logout" %}?next={{ kfet_home_url|urlencode }}" title="Déconnexion">
          <span class="glyphicon glyphicon-log-out"></span>
        </a>
      </li>
      {% elif not user.is_authenticated %}
      <li>
        <a href="{% url "cof-login" %}?next={{ request.path|urlencode }}" title="Connexion">
          <span>Connexion</span><!--
          --><span class="glyphicon glyphicon-log-in"></span>
        </a>
      </li>
      {% endif %}
    </ul>
  </div>
</nav>
