<?php
$currentPage = max(1, (int) ($saPagination['current'] ?? 1));
$totalPages = max(1, (int) ($saPagination['total_pages'] ?? 1));
$pages = sa_pagination_pages($currentPage, $totalPages);
?>
<nav class="sa-pagination" aria-label="Paginación">
    <a class="sa-page-button <?= $currentPage <= 1 ? 'is-disabled' : '' ?>" href="<?= sa_e(sa_query_url(['page' => max(1, $currentPage - 1)])) ?>">Anterior</a>
    <?php foreach ($pages as $page): ?>
        <?php if ($page === 'ellipsis'): ?>
            <span class="sa-page-ellipsis">…</span>
        <?php else: ?>
            <a class="sa-page-button <?= (int) $page === $currentPage ? 'is-active' : '' ?>" href="<?= sa_e(sa_query_url(['page' => (int) $page])) ?>"><?= (int) $page ?></a>
        <?php endif; ?>
    <?php endforeach; ?>
    <a class="sa-page-button <?= $currentPage >= $totalPages ? 'is-disabled' : '' ?>" href="<?= sa_e(sa_query_url(['page' => min($totalPages, $currentPage + 1)])) ?>">Siguiente</a>
</nav>
