{% extends "generic/generic_content.html" %}
{% load render_table from django_tables2 %}
{% load crispy_forms_tags %}
{% load generic %}
{% load i18n %}
{% load export_url from django_tables2 %}

{% block title %}
  {% blocktranslate with verbose_name_plural=object_list.model.get_verbose_name_plural %}List {{ verbose_name_plural }}{% endblocktranslate %}
{% endblock title %}

{% if filter %}

  {% block col %}
    <div class="card">
      <div class="card-header">
        <div class="row">
          <div class="col">{{ object_list.model.get_verbose_name_plural|title }}</div>
          <div class="col">
            {% if object_list.model.get_add_permission in perms %}
              <a class="btn btn-outline-success float-end btn-sm"
                 href="{{ object_list.model.get_createview_url }}">{% translate "Create" %}</a>
              <a class="btn btn-outline-success float-end btn-sm me-1"
                 href="{{ object_list.model.get_importview_url }}">{% translate "Import" %}</a>
            {% endif %}
          </div>
        </div>
      </div>
      <div class="card-body">
        {% if filter.form.errors %}<div class="alert alert-warning">{{ filter.form.errors }}</div>{% endif %}

        {% block filter %}
          {% crispy filter.form filter.form.helper %}
        {% endblock filter %}

      </div>
      <div class="card-footer text-muted">
        <a class="btn btn-outline-secondary"  href=".">{% translate "Reset filter" %}</a>
      </div>
    </div>
  {% endblock col %}

{% endif %}
{% if table %}

  {% block additionalcols %}
    <div class="col-8">
      <div class="card">
        <div class="card-header">
          {% blocktranslate count results=table.paginator.count %}{{ results }} result.{% plural %}{{ results }} results.{% endblocktranslate %}
          {% if view.export_formats %}
            <div class="d-inline-block">
              <a id="downloadMenuButton"
                 title="{% translate "download" %}"
                 role="button"
                 href="#"
                 data-bs-toggle="dropdown"
                 aria-expanded="false"><span class="material-symbols-outlined material-symbols-align">download</span></a>
              <ul class="dropdown-menu" aria-labelledby="downloadMenuButton">
                {% for format in view.export_formats %}
                  <li>
                    <a class="dropdown-item" href="{% export_url format %}">{{ format | upper }}</a>
                  </li>
                {% endfor %}
              </ul>
            </div>
          {% endif %}
        </div>
        <div class="card-body">

          {% block table %}
            {% render_table table %}
          {% endblock table %}

        </div>
      </div>
    </div>
  {% endblock additionalcols %}

{% endif %}
