<?php
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();

if ($arResult["NavPageCount"] > 1):
    ?>
    <div class="pagination-list">

        <?php if ($arResult["NavPageNomer"] > 1): ?>
            <a class="pagination-item button button--outline" href="<?= $arResult["sUrlPath"] ?>?<?= $arResult["NavQueryString"] ?>PAGEN_<?= $arResult["NavNum"] ?>=<?= $arResult["NavPageNomer"] - 1 ?>">
                <img src="<?= DEFAULT_TEMPLATE_PATH ?>/img/svg/arrow-left.svg" alt="Предыдущая страница">
            </a>
        <?php else: ?>
            <span class="pagination-item button button--outline" style="opacity: .5; pointer-events: none;">
            <img src="<?= DEFAULT_TEMPLATE_PATH ?>/img/svg/arrow-left.svg" alt="Предыдущая страница">
        </span>
        <?php endif; ?>

        <?php
        $pageWindow = 5;
        $startPage = max(1, $arResult["NavPageNomer"] - floor($pageWindow / 2));
        $endPage = min($arResult["NavPageCount"], $startPage + $pageWindow - 1);

        if ($startPage > 1):
            echo '<a class="pagination-item button button--outline" href="' . $arResult["sUrlPath"] . '?' . $arResult["NavQueryString"] . 'PAGEN_' . $arResult["NavNum"] . '=1">1</a>';
            if ($startPage > 2):
                echo '<span class="pagination-item is-middle button button--outline">...</span>';
            endif;
        endif;

        for ($i = $startPage; $i <= $endPage; $i++):
            if ($i == $arResult["NavPageNomer"]):
                echo '<span class="pagination-item is-active button button--outline">' . $i . '</span>';
            else:
                echo '<a class="pagination-item button button--outline" href="' . $arResult["sUrlPath"] . '?' . $arResult["NavQueryString"] . 'PAGEN_' . $arResult["NavNum"] . '=' . $i . '">' . $i . '</a>';
            endif;
        endfor;

        if ($endPage < $arResult["NavPageCount"]):
            if ($endPage < $arResult["NavPageCount"] - 1):
                echo '<span class="pagination-item is-middle button button--outline">...</span>';
            endif;
            echo '<a class="pagination-item button button--outline" href="' . $arResult["sUrlPath"] . '?' . $arResult["NavQueryString"] . 'PAGEN_' . $arResult["NavNum"] . '=' . $arResult["NavPageCount"] . '">' . $arResult["NavPageCount"] . '</a>';
        endif;
        ?>
        
        <?php if ($arResult["NavPageNomer"] < $arResult["NavPageCount"]): ?>
            <a class="pagination-item button button--outline" href="<?= $arResult["sUrlPath"] ?>?<?= $arResult["NavQueryString"] ?>PAGEN_<?= $arResult["NavNum"] ?>=<?= $arResult["NavPageNomer"] + 1 ?>">
                <img src="<?= DEFAULT_TEMPLATE_PATH ?>/img/svg/arrow-right.svg" alt="Следующая страница">
            </a>
        <?php else: ?>
            <span class="pagination-item button button--outline" style="opacity: .5; pointer-events: none;">
            <img src="<?= DEFAULT_TEMPLATE_PATH ?>/img/svg/arrow-right.svg" alt="Следующая страница">
        </span>
        <?php endif; ?>
    </div>
<?php endif; ?>
