{% extends 'booru/base.html' %}

{% block css %}
    {% load staticfiles %}
    <link rel="stylesheet" type="text/css" href="{% static 'booru/css/index.css' %}"/>
{% endblock %}

{% block scripts %}
{% endblock %}

{% block body %}
    {% load version_comparator %}
    <div class="container">
        <div class="row">
            <h1>Gallery: <a href="{% url 'booru:gallery_detail' gallery.id %}">{{gallery}}</a></h1>
        </div>

        <div class="mt-3 mb-3">            
            <div id="table">
                <table class="table table-striped text-center">
                    <thead>
                        <tr>
                            <th scope="col">Gallery</th>
                            <th scope="col">Tags</th>
                            <th scope="col">Date</th>
                            <th scope="col">User</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for version in page.object_list %}
                        <tr>
                            <th scope="row">
                                <a href="{{gallery.get_absolute_url}}">
                                    #{{gallery.id}}
                                </a>
                            </th>
                            <td>
                                {% version_comparator version "posts_mirror" %}
                            </td>
                            <td>
                                {{version.history_date}}
                            </td>
                            <td>
                                <a href="{% url 'booru:profile' version.history_user %}">{{version.history_user}}</a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>

        <nav aria-label="..." class="mt-5">
            <ul class="pagination">
                {% if page.has_previous %}
                    <li class="page-item">
                        <a class="page-link" href="{% url 'booru:gallery_history_page' gallery.id page.previous_page_number %}" tabindex="-1">Previous</a>
                    </li>
                {% else %}
                    <li class="page-item disabled">
                        <a class="page-link" href="#" tabindex="-1">Previous</a>
                    </li>
                {% endif %}
                {% for i in page.paginator.page_range %}
                    {% if page.number == i %}
                    <li class="page-item active">
                        <a class="page-link" href="{% url 'booru:gallery_history_page' gallery.id i %}">{{i}} <span class="sr-only">(current)</span></a>
                    </li>
                    {% elif i > page.number|add:'-3' and i < page.number|add:'3' %}
                    <li class="page-item">
                        <a class="page-link" href="{% url 'booru:gallery_history_page' gallery.id i %}">{{i}}</a>
                    </li>
                    {% endif %}
                {% endfor %}
                {% if page.has_next %}
                    <li class="page-item">
                        <a class="page-link" href="{% url 'booru:gallery_history_page' gallery.id page.next_page_number %}">Next</a>
                    </li>
                {% else %}                        
                    <li class="page-item disabled">
                        <a class="page-link" href="#">Next</a>
                    </li>
                {% endif %}
            </ul>
        </nav>
    </div>
{% endblock %}