{% comment %}
Copyright (C) 2023-2024  The Software Heritage developers
See the AUTHORS file at the top-level directory of this distribution
License: GNU Affero General Public License version 3, or any later version
See top-level LICENSE file for more information
{% endcomment %}

<div class="swh-top-bar">
  <div class="skipnav">
    <a href="#swh-web-content">Skip to main content</a>
  </div>
  <ul>
    <li class="swh-position-left">
      <div id="swh-full-width-switch-container"
           class="form-check form-switch d-none d-lg-block d-xl-block"
           role="group"
           aria-label="Display options">
        <input type="checkbox"
               class="form-check-input"
               id="swh-full-width-switch"
               onclick="swh.webapp.fullWidthToggled(event)" />
        <label class="form-check-label font-weight-normal pt-0"
               for="swh-full-width-switch">Full width</label>
      </div>
    </li>
    {% for text, url in top_bar.links.items %}
      <li class="swh-topbar-link">
        <a href="{{ url }}">{{ text }}</a>
      </li>
    {% endfor %}
    {% if "donate_link" in top_bar %}
      <li class="swh-topbar-donate-link">
        <a class="swh-donate-link" href="{{ top_bar.donate_link }}">Donate</a>
      </li>
    {% endif %}
    <li class="swh-position-right">
      {% if "server_url" in status %}
        <a href="{{ status.server_url }}"
           target="_blank"
           class="swh-current-status me-3 d-none d-lg-inline-block d-xl-inline-block">
          <span id="swh-current-status-description">Operational</span>
          <i class="swh-current-status-indicator green"></i>
        </a>
      {% endif %}
      {% if user.is_authenticated %}
        Logged in as
        {% with "/logout-page/"|add:"?next="|add:request.get_full_path|urlencode as next_url %}
          {% if 'OIDC' in user.backend %}
            <a href="{% url 'oidc-profile' %}"><strong>{{ user.username }}</strong></a>,
            <a id="swh-logout"
               href="{% url 'oidc-logout' %}?next={{ next_url }}&remote_user=1">logout</a>
          {% else %}
            <strong>{{ user.username }}</strong>,
            <form id="swh-logout-form"
                  method="post"
                  action="{% url logout_url %}?next={{ next_url }}">
              {% csrf_token %}
              <button type="submit">logout</button>
            </form>
          {% endif %}
        {% endwith %}
      {% else %}
        {% if request.resolver_match.url_name != logout_url %}
          <a id="swh-login"
             href="{% url login_url %}?next={{ request.build_absolute_uri|urlencode }}">login</a>
        {% else %}
          <a id="swh-login" href="{% url login_url %}">login</a>
        {% endif %}
      {% endif %}
    </li>
  </ul>
</div>
