{% load i18n %}

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#helpdesk-nav-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
    </div>

    <div class="collapse navbar-collapse" id="helpdesk-nav-collapse">
        {% if helpdesk_settings.HELPDESK_NAVIGATION_ENABLED and user.is_authenticated or user.is_staff %}
            <ul class="nav navbar-nav">
                <li><a href='{% url 'helpdesk_dashboard' %}'><span class="glyphicon glyphicon-dashboard"></span> <span class="nav-text">{% trans "Dashboard" %}</span></a></li>
                <li><a href='{% url 'helpdesk_list' %}'><span class="glyphicon glyphicon-tags"></span> <span class="nav-text">{% trans "Tickets" %}</span></a></li>
                <li><a href='{% url 'helpdesk_submit' %}'><span class="glyphicon glyphicon-plus"></span> <span class="nav-text">{% trans "New Ticket" %}</span></a></li>
                <li><a href='{% url 'helpdesk_report_index' %}'><span class="glyphicon glyphicon-stats"></span> <span class="nav-text"> {% trans "Stats" %}</span></a></li>
                {% if helpdesk_settings.HELPDESK_KB_ENABLED %}
                <li><a href='{% url 'helpdesk_kb_index' %}'><span class="glyphicon glyphicon-tree-deciduous"></span> <span class="nav-text">{% trans "Knowledgebase" %}</span></a></li>
                {% endif %}
                {% if user_saved_queries_ %}
                <li class="headerlink dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-filter"></span> <span class="nav-text">{% trans "Saved Query" %} <b class="caret"></b></span></a>
                    <ul class="dropdown-menu">
                        {% for q in user_saved_queries_ %}
                            <li><a href="{% url 'helpdesk_list' %}?saved_query={{ q.id }}">{{ q.title }}
                                {% if q.shared %}
                                    (Shared{% ifnotequal user q.user %} by {{ q.user.get_username }}{% endifnotequal %})
                                {% endif %}</a></li>
                        {% endfor %}
                    </ul>
                </li>
                {% endif %}
                <li class="headerlink dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-user"></span> <span class="nav-text">{{ user.get_full_name|default:user.get_username }} <b class="caret"></b></span></a>
                    <ul class="dropdown-menu">
                        <li><a href='{% url 'helpdesk_user_settings' %}'>{% trans "User Settings" %}</a></li>
{% if helpdesk_settings.HELPDESK_SHOW_CHANGE_PASSWORD and user.has_usable_password %}
                        <li><a href='{% url 'auth_password_change' %}'>{% trans "Change password" %}</a></li>
{% endif %}
                        <li class="divider"></li>
                        <li><a href='{% url 'logout' %}'>{#<span class="glyphicon glyphicon-log-out"></span> #}{% trans "Logout" %}</a></li>
                    </ul>
                </li>
            </ul>

            {% if not query %}
                    <form class="navbar-form navbar-left" id='searchform' method='get' action="{% url 'helpdesk_list' %}">
                        <div class="input-group">
                            <input type='text' name='q' size='15' class='input form-control' placeholder='{% trans "Search..." %}' id='search_query' title='{% trans "Enter a keyword, or a ticket number to jump straight to that ticket." %}'/>
                            <input type='hidden' name='status' value='1' /><input type='hidden' name='status' value='2' /><input type='hidden' name='status' value='3' />
                            <input type='hidden' name='search_type' value='header' />
                            {% csrf_token %}
                            <span class="input-group-btn">
                            <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span> Go</button>
                            </span>
                        </div>
                    </form>
            {% endif %}
        {% else %}
            {# Public menu #}
            <ul id="dropdown" class="nav navbar-nav">
                {% if helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE %}
                    <li><a href='{% url 'helpdesk_dashboard' %}'>{% trans "Dashboard" %}</a></li>
                    <li><a href='{% url 'helpdesk_submit' %}'>{% trans "Submit a Ticket" %}</a></li>
                {% else %}
                    {% if helpdesk_settings.HELPDESK_SUBMIT_A_TICKET_PUBLIC %}
                        <li><a href='{% url 'helpdesk_home' %}'>{% trans "Submit a Ticket" %}</a></li>
                    {% endif %}
                {% endif %}
                {% if helpdesk_settings.HELPDESK_KB_ENABLED %}<li><a href='{% url 'helpdesk_kb_index' %}'>{% trans "Knowledgebase" %}</a></li>{% endif %}
                {% if not request.path == '/helpdesk/login/' or user.is_authenticated %}
                    <li>{% if user.is_authenticated %}<a href='{% url 'logout' %}'>{% trans "Logout" %}</a>{% else %}<a href='{% url 'login' %}?next={% if next %}{{ next|escape }}{% else %}{% url 'helpdesk_home' %}{% endif %}'>{% trans "Log In" %}</a>{% endif %}</li>
                {% endif %}
            </ul>
        {% endif %}
    </div>
</nav>
