{% extends "wagtailadmin/base.html" %}
{% load i18n wagtailadmin_tags %}
{% block titletag %}{{ view.get_title }} {{ view.get_subtitle }}{% endblock %}

{% block content %}
    {% include "wagtailadmin/shared/header.html" with title=view.get_title subtitle=view.get_subtitle icon="doc-empty-inverse" %}

    <div class="nice-padding">
        <form method="POST" novalidate>
            {% csrf_token %}

            {% if next_url %}
                <input type="hidden" name="next" value="{{ next_url }}">
            {% endif %}

            {% for field in form.hidden_fields %}{{ field }}{% endfor %}

            <ul class="fields">
                {% block visible_fields %}
                    {% for field in form.visible_fields %}
                        <li>{% include "wagtailadmin/shared/field.html" %}</li>
                    {% endfor %}
                {% endblock %}
            </ul>

            {% include "wagtail_localize/admin/_components.html" with components=components only %}

            <ul class="fields">
                <li><input type="submit" value="{% trans 'Submit' %}" class="button" />{% if back_url %} <a href="{{ back_url }}" class="button button-secondary">{% trans "Go back" %}</a>{% endif %}</li>
            </ul>
        </form>
    </div>
{% endblock %}


{% block extra_js %}
    {{ block.super }}

    <script type="text/javascript">
        document.addEventListener('DOMContentLoaded', function() {
            var selectAll = document.querySelector('[name="select_all"]');
            var locales = document.querySelectorAll('[name="locales"]');

            selectAll.addEventListener('change', function() {
                for (var i = 0; i < locales.length; i++) {
                    locales[i].checked = selectAll.checked;
                }
            });
        });
    </script>

    {% for component_model, component_instance, component_form in components %}
        {{ component_form.media.js }}
    {% endfor %}

    <script type="text/javascript" src="{% versioned_static 'wagtail_localize/js/wagtail-localize-component-form.js' %}"></script>
{% endblock %}

{% block extra_css %}
    {{ block.super }}
    {{ form.media.css }}

    {% for component_model, component_instance, component_form in components %}
        {{ component_form.media.css }}
    {% endfor %}

    <link rel="stylesheet" href="{% versioned_static 'wagtail_localize/css/wagtail-localize-component-form.css' %}" />
{% endblock %}
