{% load i18n %}
{% load wagtailadmin_tags %}
<table class="listing{% if full_width %} full-width{% endif %}{% if moving or choosing %} chooser{% endif %}">
    {% if orderable %}
        <col width="50px" />
    {% endif %}
    <col />
    {% if show_parent %}
        <col />
    {% endif %}
    <col width="12%" />
    <col width="12%" />
    <col width="10%" />
    <thead>
        {% if moving or choosing %}
            <tr class="table-headers">
                {% if orderable %}
                    <th></th>
                {% endif %}
                <th class="title">Title</th>
                {% if show_parent %}
                    <th class="parent">{% trans 'Parent' %}</th>
                {% endif %}
                <th class="type">{% trans 'Type' %}</th>
                <th class="status">{% trans 'Status' %}</th>
                <th class="children"></th>
            </tr>
        {% endif %}
        {% if parent_page %}
            {% page_permissions parent_page as parent_page_perms %}
            <tr class="index {% if not parent_page.live %} inactive{% endif %} {% if moving or choosing %}{% if parent_page.can_choose %}can-choose{% endif %}{% endif %}">
                <td class="title" {% if orderable %}colspan="2"{% endif %}>
                    {% if moving %}
                        <h2>
                            {% if parent_page.can_choose %}
                                <a href="{% url 'wagtailadmin_pages_move_confirm' page_to_move.id parent_page.id %}">{{ parent_page.title }}</a>
                            {% else %}
                                {{ parent_page.title }}
                            {% endif %}

                            {% test_page_is_public parent_page as is_public %}
                            {% if not is_public %}
                                <span class="privacy-indicator icon icon-locked" title="This page is protected from public view"></span>
                            {% endif %}
                        </h2>
                    {% elif choosing %}
                        <h2>
                            {% if parent_page.can_choose %}
                                <a class="choose-page" href="#{{ parent_page.id }}" data-id="{{ parent_page.id }}" data-title="{{ parent_page.title }}" data-url="{{ parent_page.url }}">{{ parent_page.title }}</a>
                            {% else %}
                                {{ parent_page.title }}
                            {% endif %}

                            {% test_page_is_public parent_page as is_public %}
                            {% if not is_public %}
                                <span class="privacy-indicator icon icon-locked" title="This page is protected from public view"></span>
                            {% endif %}
                        </h2>
                    {% else %}
                        <h2>
                            {% if parent_page_perms.can_edit and 'edit' not in hide_actions|default:'' %}
                                <a href="{% url 'wagtailadmin_pages_edit' parent_page.id %}">{{ parent_page.title }}</a>
                            {% else %}
                                    {{ parent_page.title }}
                            {% endif %}
                        </h2>
                        
                        {% include "wagtailadmin/pages/_privacy_indicator.html" with page=parent_page %}

                        <ul class="actions">
                            {% if parent_page_perms.can_edit and 'edit' not in hide_actions|default:'' %}
                                <li><a href="{% url 'wagtailadmin_pages_edit' parent_page.id %}" class="button button-small">{% trans 'Edit' %}</a></li>
                            {% endif %}
                            {% if parent_page.has_unpublished_changes and 'view_draft' not in hide_actions|default:'' %}
                                <li><a href="{% url 'wagtailadmin_pages_view_draft' parent_page.id %}" class="button button-small" target="_blank">{% trans 'Draft' %}</a></li>
                            {% endif %}
                            {% if parent_page.live and not parent_page.is_root and 'view_live' not in hide_actions|default:'' %}
                                <li><a href="{{ parent_page.url }}" class="button button-small" target="_blank">{% trans 'Live' %}</a></li>
                            {% endif %}
                            {% if parent_page_perms.can_move and 'move' not in hide_actions|default:'' %}
                                <li><a href="{% url 'wagtailadmin_pages_move' parent_page.id %}" class="button button-small">{% trans 'Move' %}</a></li>
                            {% endif %}
                            {% if parent_page_perms.can_delete and 'delete' not in hide_actions|default:'' %}
                                <li><a href="{% url 'wagtailadmin_pages_delete' parent_page.id %}" class="button button-small">{% trans 'Delete' %}</a></li>
                            {% endif %}
                            {% if parent_page_perms.can_unpublish and 'unpublish' not in hide_actions|default:'' %}
                                <li><a href="{% url 'wagtailadmin_pages_unpublish' parent_page.id %}" class="button button-small">{% trans 'Unpublish' %}</a></li>
                            {% endif %}
                            {% if parent_page_perms.can_add_subpage and 'add_subpage' not in hide_actions|default:'' %}
                                <li><a href="{% url 'wagtailadmin_pages_add_subpage' parent_page.id %}" class="button button-small bicolor icon white icon-plus">{% trans 'Add child page' %}</a></li>
                            {% endif %}
                        </ul>
                    {% endif %}
                </td>
                <td class="type" valign="bottom">{{ parent_page.content_type.model_class.get_verbose_name }}</td>
                <td class="status" valign="bottom">
                    {% if not choosing and not moving and parent_page.live and not parent_page.is_root and 'view_live' not in hide_actions|default:'' %}
                        <a href="{{ parent_page.url }}" target="_blank" class="status-tag {% if parent_page.status_string != "draft" %}primary{% endif %}">{{ parent_page.status_string|capfirst }}</a>
                    {% else %}
                        <span class="status-tag {% if parent_page.status_string != "draft" %}primary{% endif %}">{{ parent_page.status_string|capfirst }}</span>
                    {% endif %}
                </td>
                <td></td>
            </tr>
        {% endif %}
    
        {% if not moving and not choosing %}
            <tr class="table-headers">
                {% if orderable %}
                    <th class="ord">
                        {% if ordering == "ord" %}
                            <a href="{% url 'wagtailadmin_explore' parent_page.id %}" class="icon icon-order text-replace" title="{% trans 'Disable ordering of child pages' %}">{% trans 'Order' %}</a></th> 
                        {% else %}
                            <a href="{% url 'wagtailadmin_explore' parent_page.id %}?ordering=ord" class="icon icon-order text-replace" title="{% trans 'Enable ordering of child pages' %}">{% trans 'Order' %}</a></th>
                        {% endif %}
                    </th>
                {% endif %}
                <th class="title">
                    {% if sortable %}
                        <a href="{% url 'wagtailadmin_explore' parent_page.id %}?ordering={% if ordering == "title" %}-{% endif %}title" class="icon icon-arrow-{% if ordering == "title" %}down-after{% elif ordering == "-title" %}up-after{% else %}down-after{% endif %} {% if ordering == "title" or ordering == "-title" %}teal{% endif %}">
                            {% trans 'Title' %}
                        </a>
                    {% else %}
                        {% trans 'Title' %}
                    {% endif %}
                </th>
                {% if show_parent %}
                    <th class="parent">Parent</th>
                {% endif %}
                <th class="type">
                    {% if sortable %}
                        <a href="{% url 'wagtailadmin_explore' parent_page.id %}?ordering={% if ordering == "content_type" %}-{% endif %}content_type" class="icon icon-arrow-{% if ordering == "-content_type" %}up-after{% else %}down-after{% endif %} {% if ordering == "content_type" or ordering == "-content_type" %}teal {% endif %}">
                            {% trans 'Type' %}
                        </a>
                    {% else %}
                        {% trans 'Type' %}
                    {% endif %}                   
                </th>
                <th class="status">
                    {% if sortable %}
                        <a href="{% url 'wagtailadmin_explore' parent_page.id %}?ordering={% if ordering == "live" %}-{% endif %}live" class="icon icon-arrow-{% if ordering == "-live" %}up-after{% else %}down-after{% endif %} {% if ordering == "live" or ordering == "-live" %}teal {% endif %}">
                            {% trans 'Status' %}
                        </a>
                    {% else %}
                        {% trans 'Status' %}
                    {% endif %}
                </th>
                <th class="children"></th>
            </tr>
        {% endif %}
    </thead>
    <tbody>
        {% if pages %}
            {% for page in pages %}
                {% page_permissions page as page_perms %}
                <tr {% if ordering == "ord" %}id="page_{{ page.id }}" data-page-title="{{ page.title }}"{% endif %} class="{% if not page.live %} inactive{% endif %}{% if moving and page.can_choose %} can-choose{% elif choosing and page.can_choose %} can-choose{% else %} cant-choose{% endif %}">
                    {% if orderable %}
                        <td class="ord">{% if ordering == "ord" %}<div class="handle icon icon-grip text-replace">{% trans 'Drag' %}</div>{% endif %}</td>
                    {% endif %}
                    <td class="title" valign="top">
                        <h2>
                            {% if moving %}
                                {% if page.can_choose %}
                                    <a href="{% url 'wagtailadmin_pages_move_confirm' page_to_move.id page.id %}">{{ page.title }}</a>
                                {% else %}
                                    {{ page.title }}
                                {% endif %}
                            {% elif choosing %}
                                {% if page.can_choose %}
                                    <a class="choose-page" href="#{{ page.id }}" data-id="{{ page.id }}" data-title="{{ page.title }}" data-url="{{ page.url }}">{{ page.title }}</a>
                                {% else %}
                                    {{ page.title }}
                                {% endif %}
                            {% else %}
                                {% if page_perms.can_edit and 'edit' not in hide_actions|default:'' %}
                                    <a href="{% url 'wagtailadmin_pages_edit' page.id %}" title="{% trans 'Edit this page' %}">{{ page.title }}</a>
                                {% else %}
                                    {{ page.title }}
                                {% endif %}
                            {% endif %}

                            {% test_page_is_public page as is_public %}
                            {% if not is_public %}
                            <span class="privacy-indicator icon icon-locked" title="This page is protected from public view"></span>
                            {% endif %}
                        </h2>
                        {% if not moving and not choosing %}
                            <ul class="actions">
                                {% if page_perms.can_edit and 'edit' not in hide_actions|default:'' %}
                                    <li><a href="{% url 'wagtailadmin_pages_edit' page.id %}" class="button button-small" title="{% trans 'Edit this page' %}">{% trans 'Edit' %}</a></li>
                                {% endif %}
                                {% if page.has_unpublished_changes and 'view_draft' not in hide_actions|default:'' %}
                                    <li><a href="{% url 'wagtailadmin_pages_view_draft' page.id %}" class="button button-small" target="_blank">{% trans 'Draft' %}</a></li>
                                {% endif %}
                                {% if page.live and 'view_live' not in hide_actions|default:'' %}
                                    <li><a href="{{ page.url }}" class="button button-small" target="_blank">{% trans 'Live' %}</a></li>
                                {% endif %}
                                {% if page_perms.can_move and 'move' not in hide_actions|default:'' %}
                                    <li><a href="{% url 'wagtailadmin_pages_move' page.id %}" class="button button-small">{% trans 'Move' %}</a></li>
                                {% endif %}
                                {% if page_perms.can_delete and 'delete' not in hide_actions|default:'' %}
                                    <li><a href="{% url 'wagtailadmin_pages_delete' page.id %}" class="button button-small">{% trans 'Delete' %}</a></li>
                                {% endif %}
                                {% if page_perms.can_unpublish and 'unpublish' not in hide_actions|default:'' %}
                                    <li><a href="{% url 'wagtailadmin_pages_unpublish' page.id %}" class="button button-small">{% trans 'Unpublish' %}</a></li>
                                {% endif %}
                                {% if page_perms.can_add_subpage and 'add_subpage' not in hide_actions|default:'' %}
                                    <li><a href="{% url 'wagtailadmin_pages_add_subpage' page.id %}" class="button button-small">{% trans 'Add child page' %}</a></li>
                                {% endif %}
                            </ul>
                        {% endif %}
                    </td>
                    {% if show_parent %}
                        {% with page.get_parent as parent %}
                            <td class="parent" valign="top">
                                {% if parent %}
                                    <a href="{% url 'wagtailadmin_explore' parent.id %}">{{ parent.title }}</a>
                                {% endif %}
                            </td>
                        {% endwith %}
                    {% endif %}
                    <td class="type" valign="top">{{ page.content_type.model_class.get_verbose_name }}</td>
                    <td class="status" valign="top">
                        {% if not choosing and not moving and page.live and 'view_live' not in hide_actions|default:'' %}
                             <a href="{{ page.url }}" target="_blank" class="status-tag {% if page.status_string != "draft" %}primary{% endif %}">{{ page.status_string }}</a>
                        {% else %}
                             <span class="status-tag {% if page.status_string != "draft" %}primary{% endif %}">{{ page.status_string }}</span>
                        {% endif %}
                    </td>
                    <td class="{% if allow_navigation %}{% if choosing %}{% if page.can_descend %} children{% endif%}{% elif moving %}{% if page.can_descend %} children{% endif%}{% elif allow_navigation and page.is_navigable %} children{% else %}no-children{% endif %}{% endif %}">
                        {% if allow_navigation %}
                            {% if moving %}
                                {% if page.can_descend %}
                                    <a href="{% url 'wagtailadmin_pages_move_choose_destination' page_to_move.id page.id %}" class="icon text-replace icon-arrow-right navigate-pages" title="{% blocktrans with title=page.title %}Explorer subpages of '{{ title }}'{% endblocktrans %}">{% trans 'Explore' %}</a>
                                {% endif %}
                            {% elif choosing %}
                                {% if page.can_descend %}
                                    <a href="{% url 'wagtailadmin_choose_page_child' page.id %}?{{ querystring }}" class="icon text-replace icon-arrow-right navigate-pages" title="{% blocktrans with title=page.title %}Explorer subpages of '{{ title }}'{% endblocktrans %}">{% trans 'Explore' %}</a>
                                {% endif %}
                            {% else %}
                                {% if page.is_navigable %}
                                    <a href="{% url 'wagtailadmin_explore' page.id %}" class="icon text-replace icon-arrow-right" title="{% blocktrans with title=page.title %}Explorer child pages of '{{ title }}'{% endblocktrans %}">{% trans "Explore" %}</a>
                                {% elif page_perms.can_add_subpage %}
                                    <a href="{% url 'wagtailadmin_pages_add_subpage' page.id %}" class="icon text-replace icon-plus-inverse" title="{% blocktrans with title=page.title %}Add a child page to '{{ title }}'{% endblocktrans %}">{% trans 'Add subpage' %}</a>
                                {% endif %}
                            {% endif %}
                        {% endif %}
                     </td>
                </tr>
            {% endfor %}
        {% else %}
            {% url 'wagtailadmin_pages_add_subpage' parent_page.id as add_page_url%}
            <tr><td colspan="3" class="no-results-message"><p>{% trans "No pages have been created." %}{% if parent_page and parent_page_perms.can_add_subpage %} {% blocktrans %}Why not <a href="{{ add_page_url }}">add one</a>?{% endblocktrans %}{% endif %}</td></tr>
        {% endif %}
    </tbody>
</table>

{% if parent_page and pages and pages.paginator %}
    <div class="pagination">
        <p>{% blocktrans with page_number=pages.number num_pages=pages.paginator.num_pages%}
            Page {{ page_number }} of {{ num_pages }}.
        {% endblocktrans %}</p>
        <ul>
            <li class="prev">
                {% if pages.has_previous %}
                    <a href="{% url 'wagtailadmin_explore' parent_page.id %}?p={{ pages.previous_page_number }}{% if ordering %}&amp;ordering={{ ordering }}{% endif %}" class="icon icon-arrow-left">{% trans "Previous" %}</a>
                {% endif %}
            </li>
            <li class="next">
                {% if pages.has_next %}
                    <a href="{% url 'wagtailadmin_explore' parent_page.id %}?p={{ pages.next_page_number }}{% if ordering %}&amp;ordering={{ ordering }}{% endif %}" class="icon icon-arrow-right-after">{% trans 'Next' %}</a>
                {% endif %}
            </li>
        </ul>
    </div>
{% endif %}
