{% extends "admin/base.html" %}
{% load paper_menu %}

{% block scripts %}
  <script src="{% url 'admin:jsi18n' %}"></script>
  {{ block.super }}
{% endblock %}

{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block sidebar %}
  <aside class="paper-sidebar bg-dark">
    <nav class="navbar navbar-dark flex-column flex-nowrap justify-content-start align-items-stretch p-0">
      {% block branding %}
        <div class="navbar-brand d-flex align-items-center text-wrap mr-0">
          <a href="{% url 'admin:index' %}" class="navbar-brand-name">{{ site_header }}</a>
        </div>
      {% endblock %}

      {% if paper.ENVIRONMENT_NAME %}
        <p class="paper-environment"
           style="--bg-color: {{ paper.ENVIRONMENT_COLOR|default:"#808080" }}">
          {{ paper.ENVIRONMENT_NAME }}
        </p>
      {% endif %}

      {% block menu %}
        <div class="paper-sidebar__menu">
          <ul id="sidebar-menu" class="paper-sidebar__item-list paper-sidebar__item-list--level-1 navbar-nav">
            {% paper_menu "#sidebar-menu" %}
          </ul>
        </div>
      {% endblock %}
    </nav>
  </aside>
{% endblock %}


{% block header %}
  <header class="paper-header sticky-top">
    <nav class="navbar navbar-expand">
      <div class="container-fluid">
        {% if has_permission %}
          {% block usertools %}
            <ul class="navbar-nav flex-wrap align-items-center flex-shrink-0 flex-grow-1">
              {% spaceless %}
                {% block header_buttons %}{% endblock %}
              {% endspaceless %}

              {% block userlinks %}
                {% if not is_popup %}
                  {# divider for mobile devices #}
                  <li class="nav-item align-self-stretch flex-grow-1 mx-0"></li>

                  <li class="nav-item">
                    <a href="{{ site_url }}"
                       class="nav-link"
                       data-toggle="tooltip"
                       data-placement="bottom"
                       data-trigger="hover"
                       data-html="true"
                       title="{{ _("View site") }}">
                      <i class="fa fa-eye"></i>
                      <span class="d-none d-sm-inline">{{ _("View site") }}</span>
                    </a>
                  </li>

                  <li class="nav-item dropdown">
                    <a href="#" id="userProfileMenu"
                       class="nav-link dropdown-toggle"
                       role="button"
                       data-toggle="dropdown"
                       aria-haspopup="true"
                       aria-expanded="false">
                        <i class="fa fa-user"></i>
                        <span class="d-none d-sm-inline">{% firstof user.get_short_name user.get_username %}</span>
                    </a>

                    <ul class="dropdown-menu dropdown-menu-right position-absolute"
                        role="menu" aria-labelledby="userProfileMenu">
                      {% if user.has_usable_password %}
                        <li role="presentation">
                          <a href="{% url 'admin:password_change' %}" class="dropdown-item" role="menuitem">
                            <i class="fa fa-fw fa-key"></i>
                            <span>{{ _("Change password") }}</span>
                          </a>
                        </li>
                      {% endif %}

                      {% if user.is_impersonate %}
                        <!-- django-impersonate support -->
                        <li role="presentation">
                          <a href="{% url 'impersonate-stop' %}" class="dropdown-item" role="menuitem">
                            <i class="fa fa-fw fa-sign-out"></i>
                            <span>{{ _("Stop impersonation") }}</span>
                          </a>
                        </li>
                      {% elif user.is_hijacked %}
                        <!-- django-hijack support -->
                        <li role="presentation">
                          <form action="{% url 'hijack:release' %}" method="POST">
                            {% csrf_token %}
                            <input type="hidden" name="next" value="{{ request.path }}">
                            <button type="submit" class="dropdown-item" role="menuitem">
                              <i class="fa fa-fw fa-sign-out"></i>
                              <span>{{ _("Stop impersonation") }}</span>
                            </button>
                          </form>
                        </li>
                      {% endif %}

                      {% if user.is_active and user.is_staff %}
                        {% url 'django-admindocs-docroot' as docsroot %}
                        {% if docsroot %}
                          <li role="presentation">
                            <a href="{{ docsroot }}" class="dropdown-item" role="menuitem">
                              <i class="fa fa-fw fa-book"></i>
                              <span>{{ _("Documentation") }}</span>
                            </a>
                          </li>
                        {% endif %}
                      {% endif %}

                      <li role="presentation">
                        <a href="{% url 'admin:logout' %}?next={% url 'admin:index' %}" class="dropdown-item" role="menuitem">
                          <i class="fa fa-fw fa-sign-out"></i>
                          <span>{{ _("Log out") }}</span>
                        </a>
                      </li>
                    </ul>
                  </li>

                  <li class="nav-item d-xl-none">
                    <a href="#" class="paper-header__burger nav-link" data-toggle="sidebar">
                      <i class="fa fa-bars"></i>
                    </a>
                  </li>
                {% endif %}
              {% endblock %}
            </ul>
          {% endblock %}
        {% endif %}
      </div>
    </nav>
  </header>
{% endblock %}


{% block breadcrumbs %}
  <nav aria-label="breadcrumb" class="paper-breadcrumbs d-none d-sm-block">
    <ol class="paper-breadcrumbs__list breadcrumb">
      <li class="breadcrumb-item">
        <a href="{% url 'admin:index' %}">
          <i class="fa fa-home mr-1"></i>
          <span>{{ _("Home") }}</span>
        </a>
      </li>

      {% block breadcrumb_items %}
        {% if title %}
          <li class="breadcrumb-item active" aria-current="page">
            <span>{{ title }}</span>
          </li>
        {% endif %}
      {% endblock breadcrumb_items %}
    </ol>
  </nav>
{% endblock %}


{% block main %}
  <div class="container-fluid d-flex flex-column flex-grow-1">
    {% spaceless %}
      <ul class="paper-messages messagelist mb-3">
        {% block messages %}
          {% for message in messages %}
            <li class="paper-message paper-message--{% firstof message.level_tag 'info' %}">
              {{ message|capfirst }}
            </li>
          {% endfor %}
        {% endblock %}
      </ul>
    {% endspaceless %}

    {% block before_content %}
      <div class="paper-page__header mb-3">
        {% block pretitle %}{% endblock %}
        {% block content_title %}
          {% firstof cl.opts.verbose_name_plural title as page_title %}
          <h1>{{ page_title|capfirst }}</h1>
        {% endblock %}
      </div>
    {% endblock %}

    {% block layout %}
      <div class="row">
        <div class="paper-page__content col">
          {% block content %}{% endblock %}
        </div>

        <div class="paper-page__toolbar col-auto">{% spaceless %}
          {% block toolbar %}{% endblock %}
        {% endspaceless %}</div>
      </div>
    {% endblock %}
  </div>
{% endblock %}


{% block footer %}
  {% if not is_popup %}
    {% include "paper_admin/footer.html" %}
  {% endif %}
{% endblock %}