<!--

    Queue - A Queueing system that can be used to handle labs in higher education
    Copyright (C) 2016-2024  Delft University of Technology

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <!--@thymesVar id="page" type="org.springframework.data.domain.Page<java.lang.Object>"-->
    <!--@thymesVar id="size" type="java.lang.Integer"-->
    <!--@thymesVar id="url" type="java.lang.String"-->

    <body>
        <nav
            th:if="${page.getTotalPages() > 1}"
            aria-label="Page navigation"
            class="pagination"
            th:fragment="pagination (page, size)"
            th:with="url=${#uri}">
            <ul role="list">
                <li th:classappend="${not page.isFirst()} ? '' : 'disabled'" class="page-item">
                    <a th:if="${page.isFirst()}">&laquo;</a>

                    <a th:if="${!page.isFirst()}" th:href="@{${url}(page=0, size=${page.getSize()})}">&laquo;</a>
                </li>

                <th:block th:if="${page.getTotalPages() < size}">
                    <li th:each="pageNumber : ${#numbers.sequence(0, page.getTotalPages()-1)}" class="page-item">
                        <a
                            th:if="${pageNumber == page.getNumber()}"
                            aria-current="page"
                            th:text="${pageNumber+1}"
                            th:href="@{${url}(page=${pageNumber}, size=${page.getSize()})}">
                            1
                        </a>
                        <a
                            th:if="${pageNumber != page.getNumber()}"
                            th:text="${pageNumber+1}"
                            th:href="@{${url}(page=${pageNumber}, size=${page.getSize()})}">
                            1
                        </a>
                    </li>
                </th:block>

                <th:block th:unless="${page.getTotalPages() < size}">
                    <th:block th:if="${page.getNumber() > size}">
                        <li class="page-item"><a href="#">...</a></li>
                    </th:block>

                    <th:block th:each="pageNumber : ${#numbers.sequence(page.getNumber() - size + 1, page.getNumber() + size - 1)}">
                        <th:block th:if="${pageNumber >= 0 and pageNumber <= page.getTotalPages()-1}">
                            <li class="page-item">
                                <a
                                    th:if="${pageNumber == page.getNumber()}"
                                    aria-current="page"
                                    th:text="${pageNumber+1}"
                                    th:href="@{${url}(page=${pageNumber}, size=${page.getSize()})}">
                                    1
                                </a>
                                <a
                                    th:if="${pageNumber != page.getNumber()}"
                                    th:text="${pageNumber+1}"
                                    th:href="@{${url}(page=${pageNumber}, size=${page.getSize()})}">
                                    1
                                </a>
                            </li>
                        </th:block>
                    </th:block>

                    <th:block th:if="${page.getNumber() + size <= page.getTotalPages()-1}">
                        <li class="page-item"><a>...</a></li>
                    </th:block>
                </th:block>

                <li th:classappend="${not page.isLast()} ? '' : 'disabled'" class="page-item">
                    <a th:if="${page.isLast()}">&raquo;</a>

                    <a th:if="${!page.isLast()}" th:href="@{${url}(page=${page.getTotalPages()-1}, size=${page.getSize()})}">&raquo;</a>
                </li>
            </ul>
        </nav>
    </body>
</html>
