{% load staticfiles %}
{% load wnsq_tags %}
{% load i18n %}
<nav class="navigation-bar fixed-top dark">
    <nav class="navigation-bar-content">
        <a href="{% url 'homepage' %}"><img class="element" src="{% static 'img/green_nose.png' %}"/></a>
        <span class="element-divider"></span>

        {% if request.user.is_authenticated %}

            <div class="element input-element">
                <form method="get" action="{% url 'search_results' %}" onsubmit="check_empty()">
                    <div class="input-control text">
                        <input type="text" placeholder="{% trans 'Search' %}" name="query" id="query">
                        <button class="btn-search"></button>
                    </div>
                </form>
            </div>


            {% if request.user|check_group:"A" %}
                <div class="element">
                    <a class="dropdown-toggle" href="#">{{ projects_vnp|capfirst }}</a>
                    <ul class="dropdown-menu" data-role="dropdown">
                        <li><a href="{% url 'projects_list' %}">{{ projects_vnp|capfirst }}</a></li>

                        <li class="divider"></li>
                        <li><a href="{% url 'clients_list' %}">{{ clients_vnp|capfirst }}</a>
                        </li>
                        <li><a href="{% url 'client offices_list' %}">{{ offices_vnp|capfirst }}</a>
                        </li>

                        <li><a href="{% url 'contact persons_list' %}">{{ contacts_vnp|capfirst }}</a>
                        </li>

                    </ul>
                </div>
            {% endif %}

            <div class="element">
                <a class="dropdown-toggle" href="#">{{ samples_vnp|capfirst }}</a>
                <ul class="dropdown-menu" data-role="dropdown">
                    <li><a href="{% url 'samples_list' %}">{% trans 'all'|capfirst %}</a></li>
                    <li><a href="{% url 'samples_list' %}?type=odour">{% trans 'Odour' %}</a>
                    </li>
                    <li><a href="{% url 'samples_list' %}?type=reference">{% trans 'Reference' %}</a></li>
                </ul>
            </div>

            <div class="element">
                <a class="dropdown-toggle" href="#">{{ panel_vnp|capfirst }}</a>
                <ul class="dropdown-menu" data-role="dropdown">
                    <li><a href="{% url 'panelists_list' %}">{% trans 'Overview' %}</a></li>
                    <li><a href="{% url 'panel_performance' %}">{% trans 'panel performance'|capfirst %}</a></li>
                    <li><a href="{% url 'labhistory' %}">{% trans 'lab performance'|capfirst %}</a></li>
                </ul>
            </div>


            <div class="element">
                <a class="dropdown-toggle" href="#">{{ measurements_vnp|capfirst }}</a>
                <ul class="dropdown-menu" data-role="dropdown">
                    <li><a href="{% url 'measurements_list' %}">{% trans 'all'|capfirst %}</a></li>
                    <li><a href="{% url 'measurements_list' %}?type=odour">{% trans 'Odour' %}</a>
                    </li>
                    <li><a href="{% url 'measurements_list' %}?type=reference">{% trans 'Reference' %}</a>
                    </li>
                </ul>
            </div>

            <div class="element">
                <a class="dropdown-toggle" href="#">{% trans 'equipment'|capfirst %}</a>
                <ul class="dropdown-menu" data-role="dropdown">
                    <li><a href="{% url 'bags_list' %}">{{ bags_vnp|capfirst }}</a></li>

                    {% if request.user|check_group:"L" %}
                        <li><a href="{% url 'reference gases_list' %}">{{ refgas_vnp|capfirst }}</a></li>
                        <li><a href="{% url 'olfactometers_list' %}">{{ olfactometers_vnp|capfirst }}</a>
                        </li>
                    {% endif %}

                </ul>
            </div>

            <!-- templates for head of, lab tech may create users with lower rights, as helpers -->
            {% if request.user|check_group:"A" %}
                <div class="element">
                    <a class="dropdown-toggle" href="#">{% trans 'System' %}</a>
                    <ul class="dropdown-menu" data-role="dropdown">
                        <li><a href="{% url 'users_list' %}">{% trans 'User Management' %}</a></li>
                        {% if request.user|check_group:"L" %}
                            <li><a href="{% url 'templates_list' %}">{% trans 'templates'|capfirst %}</a></li>
                        {% endif %}
                        <li class="divider"></li>
                        <li><a href="{% url 'about_page' %}">{% trans 'About' %}</a></li>
                    </ul>
                </div>
            {% endif %}

        {% endif %}

        {% if user.is_authenticated %}
            <div class="element">
                {% get_current_language as LANGUAGE_CODE %}
                <a href="#" class="dropdown-toggle">
                    <!-- current lang -->
                    {% with "/static/img/flags/"|add:LANGUAGE_CODE|add:".png" as lang_icon %}
                        <img src="{{ lang_icon }}"/>
                    {% endwith %}
                </a>
                <ul class="dropdown-menu compact" data-role="dropdown">
                    <form method="post" action="{% url 'set_language' %}" id="set_language_form">
                        <input type="hidden" name="language" id="hidden_lang_field"/>
                        {% csrf_token %}
                        {% get_available_languages as LANGUAGES %}
                        {% get_language_info_list for LANGUAGES as languages %}
                        {% for language in languages %}
                            <li>{% with "/static/img/flags/"|add:language.code|add:".png" as lang_icon %}
                                <a onclick="$('#hidden_lang_field').val('{{ language.code }}'); $('#set_language_form').submit();"
                                   href="#"><img src="{{ lang_icon }}"/><span
                                        class="on-right">{{ language.name }}</span></a>
                            {% endwith %}
                            </li>
                        {% endfor %}
                    </form>
                </ul>
            </div>
        {% endif %}
        <!-- user logged in, display some user menu -->
        {% if user.is_authenticated %}
            <div class="element place-right">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    {{ user.username }}
                    <span class="icon-user on-right"></span>
                </a>

                <ul class="dropdown-menu place-right" data-role="dropdown">
                    <li><a href="{% url 'change_password' %}">{% trans 'change password'|capfirst %}</a></li>
                    <li class="divider"></li>
                    <li><a href="{% url 'logout_page' %}">{% trans 'logout'|capfirst %}</a></li>
                </ul>
            </div>
        {% else %}
            <!-- user not logged in -->
            <a class="element place-right" href="{% url 'login_page' %}">{% trans 'login'|capfirst %}<span
                    class="icon-locked-2 on-right-more"></span></a>
        {% endif %}
    </nav>
</nav>

<script>
    function check_empty() {
        return false;
    }
</script>
