{% extends "wagtailadmin/base.html" %}
{% load i18n %}
{% block titletag %}Documents{% endblock %}
{% block extra_js %}
    {{ block.super }}
    <script>
        window.headerSearch = {
            url: "{% url 'wagtaildocs:index' %}",
            termInput: "#id_q",
            targetOutput: "#document-results"
        }

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

{% block content %}
    {% trans "Documents" as doc_str %}

    {% if user_can_add %}
        {% trans "Add a document" as add_doc_str %}
        {% include "wagtailadmin/shared/header.html" with title=doc_str add_link="wagtaildocs:add_multiple" icon="doc-full-inverse" add_text=add_doc_str search_url="wagtaildocs:index" %}
    {% else %}
        {% include "wagtailadmin/shared/header.html" with title=doc_str icon="doc-full-inverse" search_url="wagtaildocs:index" %}
    {% endif %}

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

        <div id="document-results" class="documents">
            {% include "wagtaildocs/documents/results.html" %}
        </div>
    </div>
{% endblock %}
