{% extends "wagtailadmin/base.html" %}
{% load wagtailimages_tags %}
{% load i18n %}

{% block titletag %}{% trans "Images" %}{% endblock %}
{% block extra_js %}
    {{ block.super }}
    <script>
        window.headerSearch = {
            url: "{% url 'wagtailimages:index' %}",
            termInput: "#id_q",
            targetOutput: "#image-results"
        }

        $(function() {
            $('#collection_chooser_collection_id').change(function() {
                this.form.submit();
            })
        });
    </script>
{% endblock %}

{% block content %}
    {% trans "Images" as im_str %}

    {% if user_can_add %}
        {% trans "Add an image" as add_img_str %}
        {% include "wagtailadmin/shared/header.html" with title=im_str add_link="wagtailimages:add_multiple" icon="image" add_text=add_img_str search_url="wagtailimages:index" %}
    {% else %}
        {% include "wagtailadmin/shared/header.html" with title=im_str icon="image" search_url="wagtailimages:index" %}
    {% endif %}

    <div class="nice-padding">
        {% if collections %}
            <form class="image-search search-bar" action="{% url 'wagtailimages:index' %}" method="GET">
                <ul class="fields">
                    {% include "wagtailadmin/shared/collection_chooser.html" %}
                </ul>
            </form>
        {% endif %}

        <div id="image-results">
            {% include "wagtailimages/images/results.html" %}
        </div>
    </div>
    
{% endblock %}
