{% extends "base.html" %}
{% load i18n %}

{% block head_title %}
    {{ entity_name_plural|capfirst }}
{% endblock %}

{% block content %}

    <div class="content-view">

    <h1>
        {{ entity_name_plural|capfirst }} <small class="text-muted">{{ total_count }}</small>
    </h1>

    <table class="table table-striped">
        <thead>
            <tr>
                {% for column, column_label in columns %}
                    <th scope="col">
                        <a href="?order_by={% if order_by == column %}-{% endif %}{{ column }}">
                            {{ column_label }}
                        </a>
                    </th>
                {% endfor %}
                {% if row_actions %}
                    <th scope="col">{% trans "Actions" %}</th>
                {% endif %}
            </tr>
        </thead>

        <tbody>
        {% for row in rows %}
            <tr>
                {% for value in row.data.values %}
                    <td>{{ value }}</td>
                {% endfor %}
                {% if row.actions %}
                    <td>
                        {% for action in row.actions %}
                            <a href="{{ action.url }}">
                                {{ action.label }}
                            </a>
                        {% endfor %}
                    </td>
                {% endif %}
            </tr>
        {% endfor %}
        </tbody>
    </table>

    {% if is_paginated %}
            <ul class="pagination justify-content-center">

                {% if not page.has_previous %}
                    <li class="page-item disabled">
                        <a class="page-link">
                            {% trans "Previous" %}
                        </a>
                    </li>
                {% else %}
                    <li class="page-item">
                        <a class="page-link" href="?page={{ page.previous_page_number }} %}">
                            {% trans "Previous" %}
                        </a>
                    </li>
                {% endif %}

                {% if page.number|add:'-3' > 1 %}
                    <li class="page-item">
                        <a class="page-link" href="?page={{ page.number|add:'-4' }}">&hellip;</a>
                    </li>
                {% endif %}

                {% for i in page.paginator.page_range %}
                    {% if page.number == i %}
                        <li class="active page-item">
                            <a href="" class="page-link">{{ i }}</a>
                        </li>
                    {% elif i > page.number|add:'-4' and i < page.number|add:'4' %}
                        <li class="page-item"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li>
                    {% endif %}
                {% endfor %}

                {% if page.paginator.num_pages > page.number|add:'3' %}
                    <li class="page-item">
                    <a class="page-link" href="?page={{ page.number|add:'4' }}">&hellip;</a></licl>
                {% endif %}

                {% if not page.has_next %}
                    <li class="page-item disabled">
                        <a class="page-link">
                            {% trans "Next" %}
                        </a>
                    </li>
                {% else %}
                    <li class="page-item">
                        <a class="page-link" href="?page={{ page.next_page_number }}">
                            {% trans "Next" %}
                        </a>
                    </li>
                {% endif %}

            </ul>

    {% endif %}

    </div>

{% endblock %}
