{% load i18n l10n wagtailadmin_tags %}

{{ self.formset.management_form }}

<ul class="multiple" id="id_{{ self.formset.prefix }}-FORMS">
    {% if self.formset.non_form_errors %}
        <li class="error-message">
            {% for error in self.formset.non_form_errors %}
                <span>{{ error|escape }}</span>
            {% endfor %}
        </li>
    {% endif %}

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

<script type="text/django-form-template" id="id_{{ self.formset.prefix }}-EMPTY_FORM_TEMPLATE">
    {% escapescript %}
        {% include "wagtailadmin/panels/inline_panel_child.html" with child=self.empty_child %}
    {% endescapescript %}
</script>

<p class="add">
    <button type="button" class="button bicolor button--icon" id="id_{{ self.formset.prefix }}-ADD">
        {% icon name="plus" wrapped=1 %}
        {% blocktrans trimmed with label=self.label|lower %}Add {{ label }}{% endblocktrans %}
    </button>
</p>

<script>
    (function() {
        var panel = InlinePanel({
            formsetPrefix: "id_{{ self.formset.prefix }}",
            emptyChildFormPrefix: "{{ self.empty_child.form.prefix }}",
            canOrder: {% if can_order %}true{% else %}false{% endif %},
            maxForms: {{ self.formset.max_num|unlocalize }}
        });

        {% for child in self.children %}
            panel.initChildControls("{{ child.form.prefix }}");
        {% endfor %}
        panel.setHasContent();
        panel.updateMoveButtonDisabledStates();
        panel.updateAddButtonState();
    })();
</script>
