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

{% block titletag %}{% trans "Redirects" %}{% endblock %}

{% block extra_js %}
    {{ block.super }}
    <script>
        window.headerSearch = {
            url: "{% url 'wagtailredirects:index' %}",
            termInput: "#id_q",
            targetOutput: "#redirects-results"
        }
    </script>
{% endblock %}

{% block content %}
    <link rel="stylesheet" type="text/css" href="{% static 'wagtailredirects/css/index.css' %}">

    {% trans "Redirects" as redirects_str %}
    {% if user_can_add %}
        {% url "wagtailredirects:add" as add_link %}
        {% trans "Add redirect" as add_str %}
        {% url "wagtailredirects:start_import" as import_link %}
        {% url "wagtailredirects:report" as report_link %}
        {% trans "Import redirects" as import_str %}
        {% trans "Export redirects" as export_str %}

        <header class="hasform">
            {% block breadcrumb %}{% endblock %}
            <div class="row">
                <div class="left">
                    <div class="col">
                        <h1>{% icon name="redirect" %}{{ redirects_str }}</h1>
                    </div>
                    <form class="col search-form" action="{% url "wagtailredirects:index" %}{% if query_parameters %}?{{ query_parameters }}{% endif %}" method="get" novalidate role="search">
                        <ul class="fields">
                            {% for field in search_form %}
                                {% include "wagtailadmin/shared/field_as_li.html" with field=field field_classes="field-small iconfield" icon="search" %}
                            {% endfor %}
                            <li class="submit visuallyhidden"><input type="submit" value="Search" class="button" /></li>
                        </ul>
                    </form>
                </div>
                <div class="right has-multiple-actions">
                    <div class="actionbutton">
                        <a href="{{ add_link }}" class="button bicolor button--icon">{% icon name="plus" wrapped=1 %}{{ add_str }}</a>
                    </div>

                    <div class="dropdown dropdown-button match-width">
                        <a href="{{ import_link }}" class="button bicolor button--icon">{% icon name="doc-full-inverse" wrapped=1 %}{{ import_str }}</a>
                        <div class="dropdown-toggle">{% icon name="arrow-down" %}</div>
                        <ul>
                            <li><a class="button bicolor button--icon" href="{{ report_link }}">{% icon name="download" wrapped=1 %}{{ export_str }}</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </header>
    {% else %}
        {% include "wagtailadmin/shared/header.html" with title=redirects_str icon="redirect" search_url="wagtailredirects:index" %}
    {% endif %}

    <div class="nice-padding">
        <div id="redirects-results" class="redirects">
            {% include "wagtailredirects/results.html" %}
        </div>
    </div>

{% endblock %}
