{% load i18n %}
{% load firstof from future %}
{% load dashboard_extras %}

{% comment %}
Partial: App-wide header element
{% endcomment %}

{% include "_skip_link.html" with content_id="content" %}
<header class="navbar navbar-default" id="nav">
  <div class="grid-container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-nav">
        <span class="sr-only">{% trans 'Toggle navigation' %}</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>

      {% include 'brand.html' with class_prefix='navbar' %}
      {% if course_id %}
      <ul class="nav navbar-nav">
        <li>
            {% captureas course_home_url %}{% url 'courses:home' course_id=course_id %}{% endcaptureas %}
            <a href="{{ course_home_url }}" class="navbar-link active-course-name"
                data-track-type="click" data-track-event="edx.bi.ui.menu.navigated"
                data-track-text="{% firstof course_name course_id %}"
                data-track-url="{{ course_home_url }}" data-track-target-scope="course"
                data-track-target-lens="home" data-track-menu-depth="home" data-track-link-name="course_title">
                {% firstof course_name course_id %}</a>
        </li>
      </ul>
      {% endif %}
    </div>

    <div class="collapse navbar-collapse" id="main-nav">
      <ul class="nav navbar-nav navbar-right">
        {% if help_url %}
          <li>
            <a id="help" class="navbar-link " data-track-type="click" data-track-event="edx.bi.help.clicked"
               href="{{ help_url }}" target="_blank">{% trans "Help" %}</a>
          </li>
        {% endif %}
        <li class="dropdown">
          <button class="dropdown-toggle active-user navbar-link" data-toggle="dropdown"
             aria-controls="userDropdownMenu" id="userMenu">
            <span class="sr-only">{% trans "Menu for" %}</span>
            <span class="ico-user fa fa-graduation-cap" aria-hidden="true"></span>
            <span class="active-user-name">{{ request.user.username }}</span>
            <span class="ico ico-indicator fa fa-caret-down" aria-hidden="true"></span>
          </button>

          <ul id="userDropdownMenu" class="dropdown-menu active-user-nav" tabindex="-1"
              aria-labelledby="userMenu">
            <li>
              {% captureas logout_url %}{% url 'logout' %}{% endcaptureas %}
              <a class="active-user-nav-logout" href="{{ logout_url }}" data-track-type="click"
                  data-track-event="edx.bi.ui.menu.navigated" data-track-text="Logout"
                  data-track-url="{{ logout_url }}" data-track-target-scope="insights"
                  data-track-target-lens="logout" data-track-menu-depth="home" data-track-link-name="logout">
                  {% trans "Logout" %}</a>
            </li>
          </ul>
        </li>
      </ul>
    </div>
    <!-- / navbar-collapse -->
  </div>
  <!-- / container -->
</header>
<!-- / navbar -->
