{% load i18n %}
{% load core_tags %}
{% load accounts_tags %}
{% load rules %}

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="{% url 'home' %}">{{ request.site.name }}</a>
        </div>
        <div class="collapse navbar-collapse" id="navbar-collapse">
            <ul class="nav navbar-nav">
                {% back_to_project_link %}

                {% has_perm 'questions.view_catalog' request.user as can_view_catalog %}
                {% has_perm 'domain.view_attribute' request.user as can_view_attribute %}
                {% has_perm 'options.view_optionset' request.user as can_view_optionset %}
                {% has_perm 'conditions.view_condition' request.user as can_view_condition %}
                {% has_perm 'tasks.view_task' request.user as can_view_task %}
                {% has_perm 'views.view_view' request.user as can_view_view %}

                {% if can_view_catalog or can_view_attribute or can_view_optionset or can_view_condition or can_view_task or can_view_view %}
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                        {% trans 'Management' %}<span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu">
                        {% if can_view_catalog %}
                        <li>
                            <a href="{% url 'catalogs' %}">{% trans 'Questions' %}</a>
                        </li>
                        {% endif %}
                        {% if can_view_attribute %}
                        <li>
                            <a href="{% url 'domain' %}">{% trans 'Domain' %}</a>
                        </li>
                        {% endif %}
                        {% if can_view_optionset %}
                        <li>
                            <a href="{% url 'options' %}">{% trans 'Options' %}</a>
                        </li>
                        {% endif %}
                        {% if can_view_condition %}
                        <li>
                            <a href="{% url 'conditions' %}">{% trans 'Conditions' %}</a>
                        </li>
                        {% endif %}
                        {% if can_view_task %}
                        <li>
                            <a href="{% url 'tasks' %}">{% trans 'Tasks' %}</a>
                        </li>
                        {% endif %}
                        {% if can_view_view %}
                        <li>
                            <a href="{% url 'views' %}">{% trans 'Views' %}</a>
                        </li>
                        {% endif %}
                    </ul>
                </li>
                {% endif %}
                {% if user.is_superuser %}
                <li>
                    <a href="{% url 'admin:index' %}">{% trans 'Admin' %}</a>
                </li>
                {% endif %}
            </ul>

            <ul class="nav navbar-nav navbar-right">
                <li>
                    <p class="navbar-text">
                        <pending></pending>
                    </p>
                </li>

                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% trans 'Language' %}<span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        {% i18n_switcher %}
                    </ul>
                </li>

                {% if user.is_authenticated %}

                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% full_name user %}<span class="caret"></span></a>
                    <ul class="dropdown-menu">

                        {% url 'about' as about_url %}
                        {% if about_url %}
                        <li>
                            <a href="{{ about_url }}">
                                {% trans 'About RDMO' %}
                            </a>
                        </li>
                        <li role="separator" class="divider"></li>
                        {% endif %}

                        {% if settings.PROFILE_UPDATE %}
                        <li>
                            <a href="{% url 'profile_update' %}">
                                {% trans 'Update profile' %}
                            </a>
                        </li>
                        {% endif %}

                        {% if settings.ACCOUNT %}
                            {% include 'core/base_navigation_account.html' %}
                        {% endif %}

                        {% if settings.SOCIALACCOUNT %}
                            {% include 'core/base_navigation_socialaccount.html' %}
                        {% endif %}

                        {% if settings.PROFILE_DELETE %}
                        <li>
                            <a href="{% url 'profile_remove' %}">
                                {% trans 'Delete profile' %}
                            </a>
                        </li>
                        {% endif %}

                        <li>
                            <a href="{% url 'reset_overlays' %}">
                                {% trans 'Reset tutorial overlays' %}
                            </a>
                        </li>

                        <li role="separator" class="divider"></li>

                        {% if settings.ACCOUNT or settings.SOCIALACCOUNT %}
                        <li>
                            {% include 'account/logout_form.html' %}
                        </li>
                        {% else %}
                        <li>
                            <a href="{{ settings.LOGOUT_URL }}">
                                {% trans 'Logout' %}
                            </a>
                        </li>
                        {% endif %}
                    </ul>
                </li>

                {% else %}

                <li>
                    <a href="{{ settings.LOGIN_URL }}">
                        {% trans 'Login' %}
                    </a>
                </li>

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