{% load i18n l10n wagtailadmin_tags %}

{{ self.formset.management_form }}

{% if self.formset.non_form_errors %}
    <div class="error-message">
        {% for error in self.formset.non_form_errors %}
            <span>{{ error|escape }}</span>
        {% endfor %}
    </div>
{% endif %}

{% if self.help_text %}
    {% help_block status="info" %}{{ self.help_text }}{% endhelp_block %}
{% endif %}

<div id="id_{{ self.formset.prefix }}-FORMS">
    {% comment %}

    Child elements of this div will become orderable elements. Do not place additional
    "furniture" elements here unless you intend them to be part of the child ordering.

    {% endcomment %}

    {% for child in self.children %}
        {% include "wagtailadmin/panels/inline_panel_child.html" %}
    {% endfor %}
</div>

<template id="id_{{ self.formset.prefix }}-EMPTY_FORM_TEMPLATE">
    {% include "wagtailadmin/panels/inline_panel_child.html" with child=self.empty_child %}
</template>

{# Align with guiding line of the preceding child panel. #}
<div class="w-mb-4 -w-ml-4">
    {% block add_button %}
        <button type="button" class="button button-small button-secondary chooser__choose-button" id="id_{{ self.formset.prefix }}-ADD">
            {% icon name=icon|default:"plus-inverse" %}{% blocktrans trimmed with label=self.label %}Add {{ label }}{% endblocktrans %}
        </button>
    {% endblock %}
</div>

{% block js_init %}
    <script>
        (function() {
            var panel = new InlinePanel(JSON.parse("{{options_json|escapejs}}"));
        })();
    </script>
{% endblock %}
