<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
</head>

<body>
<div th:fragment="pagination">
    <nav aria-label="Page navigation">
        <ul class="pagination"
            th:with="index_diff=0,offset_minus2=${ page.getNumber() - 1}, offset_minus1=${ page.getNumber() }, current_page=${ page.getNumber() + 1 }, offset_plus1=${ page.getNumber() + 2 }, offset_plus2=${ page.getNumber() + 3}">
            <li class="page-item" th:classappend="${ current_page == 1}?'disabled'">
                <a class="page-link" href="#" th:attr="onclick=|${jsFunction}(1,${page.getSize()});|">
                    <span aria-hidden="true">처음</span>
                </a>
            </li>
            <li class="page-item" th:if="${ offset_minus2 > 0}">
                <a class="page-link" href="#" th:attr="onclick=|${jsFunction}(${offset_minus2 - index_diff },${page.getSize()});|">
                    <span aria-hidden="true" th:text="${offset_minus2}"></span>
                </a>
            </li>
            <li class="page-item" th:if="${ offset_minus1 > 0}">
                <a class="page-link" href="#" th:attr="onclick=|${jsFunction}(${offset_minus1 - index_diff },${page.getSize()});|">
                    <span aria-hidden="true" th:text="${offset_minus1 }"></span>
                </a>
            </li>
            <li class="page-item disabled">
                <a class="page-link" style="font-weight: bold" th:text="${current_page}"></a>
            </li>
            <li class="page-item" th:if="${offset_plus1 <= page.getTotalPages()}">
                <a class="page-link" href="#" th:attr="onclick=|${jsFunction}(${offset_plus1 - index_diff },${page.getSize()});|">
                    <span aria-hidden="true" th:text="${offset_plus1}"></span>
                </a>
            </li>
            <li class="page-item" th:if="${offset_plus2 <= page.getTotalPages()}">
                <a class="page-link" href="#" th:attr="onclick=|${jsFunction}(${offset_plus2 - index_diff },${page.getSize()});|">
                    <span aria-hidden="true" th:text="${offset_plus2}"></span>
                </a>
            </li>
            <li class="page-item" th:classappend="${ (page.getTotalPages()) - current_page <= 0 } ? 'disabled'">
                <a class="page-link" href="#" th:attr="onclick=|${jsFunction}(${page.getTotalPages() - index_diff },${page.getSize()});|">
                    <span aria-hidden="true">마지막</span>
                </a>
            </li>
        </ul>
        <div>
            [총 <span th:text="${page.getTotalElements()}"></span>건, <span th:text="${page.getNumber() + 1}"></span>/<span th:text="${page.getTotalPages()}"></span>페이지]
        </div>
    </nav>
    <script>

    </script>
</div>

</body>

</html>
