{% extends "wagtailsnippets/snippets/index.html" %}
{% load i18n wagtailadmin_tags wagtail_airtable_tags %}

{% block content %}
    {% wagtail_major_version as wagtail_major_version %}
    {% if wagtail_major_version < 6 %}
        {% include 'wagtailadmin/shared/headers/slim_header.html' %}
        {% fragment as base_action_locale %}{% if locale %}{% include 'wagtailadmin/shared/locale_selector.html' with theme="large" %}{% endif %}{% endfragment %}
        {% fragment as action_url_add_snippet %}{% if can_add_snippet %}{% url view.add_url_name %}{% if locale %}?locale={{ locale.language_code }}{% endif %}{% endif %}{% endfragment %}
        {% fragment as action_text_snippet %}{% blocktrans trimmed with snippet_type_name=model_opts.verbose_name %}Add {{ snippet_type_name }}{% endblocktrans %}{% endfragment %}

        {% fragment as extra_actions %}
            {% if view.list_export %}
                {% include view.export_buttons_template_name %}
            {% endif %}
        {# begin wagtail-airtable customisation for Wagtail 5.2 #}
            {% can_import_model model_opts.label as can_import_model %}
            {% if can_add_snippet and can_import_model %}
                <form action="{% url 'airtable_import_listing' %}" method="post">
                    {% csrf_token %}
                    <input type="hidden" name="model" value="{{ model_opts.label }}" />
                    <input type="hidden" name="next" value="{{ request.path }}" />
                    <button type="submit" class="button button-longrunning" data-controller="w-progress" data-action="w-progress#activate" data-w-progress-active-value="{% trans "Importing..." %}">
                        {% icon name="spinner" %}
                        <em data-w-progress-target="label">{% blocktrans with snippet_type_name=model_opts.verbose_name_plural %}Import {{ snippet_type_name }}{% endblocktrans %}</em>
                    </button>
                </form>
            {% endif %}
        {# end wagtail-airtable customisation #}
        {% endfragment %}

        {% include 'wagtailadmin/shared/header.html' with title=model_opts.verbose_name_plural|capfirst icon=header_icon search_url=search_url base_actions=base_action_locale action_url=action_url_add_snippet action_icon="plus" action_text=action_text_snippet extra_actions=extra_actions search_results_url=index_results_url %}
        <div class="nice-padding{% if filters %} filterable{% endif %}">
            <div id="listing-results" class="snippets">
                {% include "wagtailsnippets/snippets/index_results.html" %}
            </div>
            {% if filters %}
                {% include "wagtailadmin/shared/filters.html" %}
            {% endif %}
            {% trans "Select all snippets in listing" as select_all_text %}
            {% include 'wagtailadmin/bulk_actions/footer.html' with select_all_obj_text=select_all_text app_label=model_opts.app_label model_name=model_opts.model_name objects=page_obj %}
        </div>
    {% else %}
        {{ block.super }}
    {% endif %}
{% endblock %}
