{% extends "wagtailadmin/base.html" %}
{% load i18n wagtailadmin_tags %}
{% block titletag %}{% blocktrans trimmed with snippet_type_name_plural=model_opts.verbose_name_plural|capfirst %}Snippets {{ snippet_type_name_plural }}{% endblocktrans %}{% endblock %}
{% block bodyclass %}model-{{ model_opts.model_name }}{% endblock %}

{% block extra_js %}
    <script>
        window.headerSearch = {
            url: "{% url view.index_results_url_name %}",
            termInput: "#id_q",
            targetOutput: "#snippet-results"
        }
        window.wagtailConfig.BULK_ACTION_ITEM_TYPE = 'SNIPPET';
    </script>
    <script defer src="{% versioned_static 'wagtailadmin/js/bulk-actions.js' %}"></script>
{% endblock %}

{% block content %}
    {% include 'wagtailsnippets/snippets/headers/list_header.html' %}

    <header class="w-header">
        <div class="row">
            <div class="left">
                <div class="col">
                    <h1 class="w-header__title">
                        {% icon class_name="w-header__glyph" name="snippet" %} {{ model_opts.verbose_name_plural|capfirst }}
                    </h1>
                </div>
                {% if is_searchable and search_url %}
                    <form class="col search-form" action="{% url search_url %}" method="get" novalidate>
                        {% for field in search_form %}
                            {% include "wagtailadmin/shared/field.html" with field=field classname="w-mb-0" sr_only_label=True icon="search" %}
                        {% endfor %}
                        <div class="submit visuallyhidden"><input type="submit" value="Search" class="button" /></div>
                    </form>
                {% endif %}
                {% if locales %}
                    <div class="col">

                    </div>
                {% endif %}
            </div>
            <div class="right col">
                <form>
                    {% if locale %}
                        {% include 'wagtailadmin/shared/locale_selector.html' with class='c-dropdown--large' %}
                    {% endif %}
                    {% if can_add_snippet %}
                        <a href="{% url view.add_url_name %}{% if locale %}?locale={{ locale.language_code }}{% endif %}" class="button bicolor button--icon">
                            {% icon name="plus" wrapped=1 %}
                            {% blocktrans trimmed with snippet_type_name=model_opts.verbose_name %}Add {{ snippet_type_name }}{% endblocktrans %}</a>
                        {# TODO: figure out a way of saying "Add a/an [foo]" #}
                    {% endif %}
                </form>
            </div>
        </div>
    </header>

    <div class="nice-padding{% if filters %} filterable{% endif %}">
        <div id="snippet-results" class="snippets">
            {% include "wagtailsnippets/snippets/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>
{% endblock %}
