{% extends "admin/base_site.html" %}
{% load i18n admin_urls %}
{% load paper_modify %}

{% block styles %}
  {{ block.super }}
  {{ media.css }}
{% endblock %}

{% block scripts %}
  {# JavaScript for prepopulated fields #}
  {% prepopulated_fields_js %}

  {{ block.super }}
  {{ media.js }}
{% endblock %}

{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} change-form{% endblock %}


{% block header_buttons %}
  {% include 'paper_admin/header_buttons.html' %}
{% endblock %}


{% block breadcrumb_items %}
  <li class="breadcrumb-item">
    <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
  </li>

  <li class="breadcrumb-item">
    {% if has_view_permission %}
      <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
    {% else %}
      <span>{{ opts.verbose_name_plural|capfirst }}</span>
    {% endif %}
  </li>

  <li class="breadcrumb-item active" aria-current="page">
    {% if add %}
      {% blocktrans with name=opts.verbose_name %}Add {{ name }}{% endblocktrans %}
    {% else %}
      <span>{{ original|truncatewords:"18" }}</span>
    {% endif %}
  </li>
{% endblock breadcrumb_items %}


{% block messages %}
  {{ block.super }}

  {% for error in adminform.form.non_field_errors %}
    <li class="paper-message paper-message--error">
      {{ error }}
    </li>
  {% endfor %}
{% endblock %}


{% block content_title %}
  <h1>
    {% if add %}
      {% blocktrans with name=opts.verbose_name %}Add {{ name }}{% endblocktrans %}
    {% else %}
      {{ opts.verbose_name|capfirst }}: <span class="text-secondary">{{ original|truncatewords:"18" }}</span>
    {% endif %}
  </h1>
{% endblock %}


{% block before_content %}
  {{ block.super }}

  {% if tabs %}
    <div class="paper-tabs mb-3">
      <ul class="nav nav-pills " role="tablist">
        {% for tab in tabs %}
          <li class="nav-item">
            <a class="btn nav-link{% if tab.invalid %} btn-outline-danger{% else %} btn-outline-primary{% endif %}{% if tab.active %} active{% endif %}"
               id="{{ tab.name }}-tab" href="#{{ tab.name }}-panel" role="tab" data-toggle="tab"
               aria-controls="{{ tab.name }}-panel" aria-selected="{{ tab.active|yesno:"true,false" }}">
              {{ tab.title }}
            </a>
          </li>
        {% endfor %}
      </ul>
    </div>
  {% endif %}
{% endblock %}


{% block toolbar %}
  <div class="paper-toolbar sticky-top">
    <div class="paper-card card">
      <h3 class="card-header">{{ _("Toolbar") }}</h3>
      <div class="card-body">
        <ul class="list-default">
          {% block object-tools-items %}
            {% include "admin/change_form_object_tools.html" %}
          {% endblock %}
        </ul>
      </div>
    </div>
  </div>
{% endblock %}


{% block content %}
  <form action="{{ form_url }}"
        method="post"
        class="paper-form paper-form--hook"
        id="{{ opts.model_name }}_form"
        novalidate
        {% if has_file_field %} enctype="multipart/form-data"{% endif %}>
    {% csrf_token %}

    {% block form_top %}{% endblock %}

    {% if is_popup %}
      <input type="hidden" name="{{ is_popup_var }}" value="1" />
    {% endif %}
    {% if to_field %}
      <input type="hidden" name="{{ to_field_var }}" value="{{ to_field }}" />
    {% endif %}

    {% block field_sets %}
      {% if tabs %}
        <div class="tab-content">
          {% for tab in tabs %}
            <div class="tab-pane{% if tab.active %} active{% endif %}" id="{{ tab.name }}-panel"
                 role="tabpanel" aria-labelledby="{{ tab.name }}-tab">
              {% for fieldset in tab.fieldsets %}
                {% if fieldset.has_visible_field %}
                  <fieldset class="paper-card card mb-3 {{ fieldset.classes }}">
                    {% include "admin/includes/fieldset.html" %}
                  </fieldset>
                {% else %}
                  <fieldset class="{{ fieldset.classes }}" hidden>
                    {% include "admin/includes/fieldset.html" %}
                  </fieldset>
                {% endif %}
              {% endfor %}

              {% for inline_admin_formset in tab.inline_formsets %}
                {% include inline_admin_formset.opts.template %}
              {% endfor %}
            </div>
          {% endfor %}
        </div>
      {% else %}
        {% for fieldset in adminform %}
          {% if fieldset.has_visible_field %}
            <fieldset class="paper-card card mb-3 {{ fieldset.classes }}">
              {% include "admin/includes/fieldset.html" %}
            </fieldset>
          {% else %}
            <fieldset class="{{ fieldset.classes }}" hidden>
              {% include "admin/includes/fieldset.html" %}
            </fieldset>
          {% endif %}
        {% endfor %}

        {% for inline_admin_formset in inline_admin_formsets %}
          {% include inline_admin_formset.opts.template %}
        {% endfor %}
      {% endif %}
    {% endblock %}

    {% block after_related_objects %}{% endblock %}
  </form>
{% endblock %}
