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

{% block bodyclass %}modeladmin{% endblock %}

{% block titletag %}{{ view.get_meta_title }}{% endblock %}

{% block css %}
    {{ block.super }}
    {{ view.media.css }}
{% endblock %}

{% block extra_js %}
    {{ block.super }}
    {{ view.media.js }}
{% endblock %}

{% block content %}
    {% block header %}
        <header class="w-header w-header--hasform">
            {% block breadcrumb %}{% endblock %}
            <div class="row">
                <div class="left header-left">
                    <div class="col">
                        {% block h1 %}
                            <h1 class="w-header__title">
                                {% if view.header_icon %}{% icon class_name="w-header__glyph" name=view.header_icon %}{% endif %}
                                {{ view.get_page_title }}
                                {% if view.get_page_subtitle %} <span class="w-header__subtitle">{{ view.get_page_subtitle }}</span> {% endif %}
                                {% include 'modeladmin/includes/result_count.html' %}
                            </h1>
                        {% endblock %}
                    </div>
                    {% block search %}{% search_form %}{% endblock %}
                </div>
                {% block header_extra %}
                    <div class="right header-right">
                        {% if view.list_export or user_can_create %}
                            <div class="actionbutton">
                                {% if user_can_create %}
                                    {% include 'modeladmin/includes/button.html' with button=view.button_helper.add_button %}
                                {% endif %}
                                {% if view.list_export %}
                                    <div class="dropdown dropdown-button match-width col">
                                        <a href="?export=xlsx&{{ request.GET.urlencode }}" class="button bicolor button--icon">{% icon name="download" wrapped=1 %}{% trans 'Download XLSX' %}</a>
                                        <div class="dropdown-toggle">{% icon name="arrow-down" %}</div>
                                        <ul>
                                            <li><a  class="button bicolor button--icon" href="?export=csv&{{ request.GET.urlencode }}">{% icon name="download" wrapped=1 %}{% trans 'Download CSV' %}</a></li>
                                        </ul>
                                    </div>
                                {% endif %}
                            </div>
                        {% endif %}
                    </div>
                {% endblock %}
            </div>
            {% block extra_rows %}{% endblock %}
        </header>
    {% endblock %}

    {% block content_main %}
        <div class="main-content">
            <div class="row">
                {% block content_cols %}

                    {% block filters %}
                        {% if view.has_filters and all_count %}
                            <div class="changelist-filter col3">
                                <h2>{% trans 'Filter' %}</h2>
                                {% for spec in view.filter_specs %}{% admin_list_filter view spec %}{% endfor %}
                            </div>
                        {% endif %}
                    {% endblock %}

                    <div class="result-list {% if view.has_filters and all_count %}col9{% else %}col12{% endif %}">
                        {% block result_list %}
                            {% if not all_count %}
                                <div class="nice-padding" style="margin-top:30px;">
                                    {% if no_valid_parents %}
                                        <p>{% blocktrans trimmed with view.verbose_name_plural as name %}No {{ name }} have been created yet. One of the following must be created before you can add any {{ name }}:{% endblocktrans %}</p>
                                        <ul>
                                            {% for type in required_parent_types %}<li><b>{{ type|title }}</b></li>{% endfor %}
                                        </ul>
                                    {% else %}
                                        <p>{% blocktrans trimmed with view.verbose_name_plural as name %}No {{ name }} have been created yet.{% endblocktrans %}
                                            {% if user_can_create %}
                                                {% blocktrans trimmed with view.create_url as url %}
                                                    Why not <a href="{{ url }}">add one</a>?
                                                {% endblocktrans %}
                                            {% endif %}</p>
                                    {% endif %}
                                </div>
                            {% else %}
                                {% result_list %}
                            {% endif %}
                        {% endblock %}
                    </div>

                    {% block pagination %}
                        <nav class="pagination {% if view.has_filters and all_count %}col9{% else %}col12{% endif %}" aria-label="{% trans 'Pagination' %}">
                            <p>{% blocktrans trimmed with page_obj.number as current_page and paginator.num_pages as num_pages %}Page {{ current_page }} of {{ num_pages }}.{% endblocktrans %}</p>
                            {% if paginator.num_pages > 1 %}
                                <ul>
                                    {% pagination_link_previous page_obj view %}
                                    {% pagination_link_next page_obj view %}
                                </ul>
                            {% endif %}
                        </nav>
                    {% endblock %}

                {% endblock %}
            </div>
        </div>
    {% endblock %}

{% endblock %}
