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

{% block titletag %}{% blocktrans with title=page.get_admin_display_title %}Comparing {{ title }}{% endblocktrans %}{% endblock %}

{% block content %}
    {% trans "Comparing" as comparing_str %}
    {% include "wagtailadmin/shared/header.html" with title=comparing_str subtitle=page.get_admin_display_title icon="doc-empty-inverse" %}

    <div class="nice-padding">

        <p>
            <a href="{% url 'wagtailadmin_pages:edit' page.id %}" class="button button-small">{% trans "Edit this page" %}</a>
            <a href="{% url 'wagtailadmin_pages:revisions_index' page.id %}" class="button button-small button-secondary">{% trans "View revisions" %}</a>
        </p>


        <table class="listing">
            <col width="15%" />
            <col />

            <thead>
                <tr>
                    <th>{% trans "Fields" %}</th>
                    <th>{% trans "Changes" %}</th>
                </tr>
            </thead>

            <tbody>
                {% for comp in comparison %}
                    <tr>
                        <td class="title" valign="top">
                            <h2>{{ comp.field_label }}:</h2>
                        </td>
                        <td class="comparison{% if not comp.is_field %} no-padding{% endif %}">
                            {% if comp.is_field %}
                                {{ comp.htmldiff }}
                            {% elif comp.is_child_relation %}
                                {% for child_comp in comp.get_child_comparisons %}
                                    <div class="comparison__child-object {% if child_comp.is_addition %}addition{% elif child_comp.is_deletion %}deletion{% endif %}">
                                        {% with child_comp.get_position_change as move %}
                                            {% if move %}
                                            <div class="help-block help-info">
                                                <p>
                                                    {% if move > 0 %}
                                                        {% blocktrans count counter=move %}
                                                            Moved down 1 place.
                                                        {% plural %}
                                                            Moved down {{ counter }} places.
                                                        {% endblocktrans %}
                                                    {% elif move < 0 %}
                                                        {% blocktrans count counter=move|abs %}
                                                            Moved up 1 place.
                                                        {% plural %}
                                                            Moved up {{ counter }} places.
                                                        {% endblocktrans %}
                                                    {% endif %}
                                                </p>
                                            </div>
                                            {% endif %}
                                        {% endwith %}

                                        <dl class="comparison__list">
                                            {% for field_comp in child_comp.get_field_comparisons %}
                                                <dt>{{ field_comp.field_label }}</dt>
                                                <dd>{{ field_comp.htmldiff }}</dd>
                                            {% endfor %}
                                        </dl>
                                    </div>
                                {% endfor %}
                            {% endif %}
                        </td>
                    </tr>
                {% empty %}
                    <tr>
                        <td colspan="2" class="no-results-message">
                            <p>{% trans "There are no differences between these two revisions" %}</p>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}


{% block extra_css %}
    {{ block.super }}
    <link rel="stylesheet" href="{% static 'wagtailadmin/css/layouts/compare-revisions.css' %}" type="text/css" />
{% endblock %}
