<?php

declare(strict_types=1);

/**
 * N 幣歷程分頁（member_profile.php）。
 *
 * @var int $ncoinPage
 * @var int $ncoinPages
 * @var list<int|null> $ncoinPagerItems
 * @var Closure $buildNcoinPageUrl
 * @var string $ncoinPagerPosition 'top'|'bottom'
 */

if ($ncoinPages <= 1) {
    return;
}

$posClass = match ($ncoinPagerPosition ?? 'bottom') {
    'top' => ' member-profile-ncoin-pager--top',
    default => ' member-profile-ncoin-pager--bottom',
};

?>
<nav class="pager member-profile-ncoin-pager<?= $posClass ?>" aria-label="<?= $ncoinNameEsc ?>歷程分頁">
    <?php if ($ncoinPage > 1): ?>
        <a href="<?= htmlspecialchars($buildNcoinPageUrl($ncoinPage - 1), ENT_QUOTES, 'UTF-8') ?>">上一頁</a>
    <?php else: ?>
        <span class="disabled">上一頁</span>
    <?php endif; ?>

    <?php foreach ($ncoinPagerItems as $item): ?>
        <?php if ($item === null): ?>
            <span class="member-profile-ncoin-pager__gap" aria-hidden="true">…</span>
        <?php elseif ($item === $ncoinPage): ?>
            <span class="cur" aria-current="page"><?= (int) $item ?></span>
        <?php else: ?>
            <a href="<?= htmlspecialchars($buildNcoinPageUrl((int) $item), ENT_QUOTES, 'UTF-8') ?>"><?= (int) $item ?></a>
        <?php endif; ?>
    <?php endforeach; ?>

    <?php if ($ncoinPage < $ncoinPages): ?>
        <a href="<?= htmlspecialchars($buildNcoinPageUrl($ncoinPage + 1), ENT_QUOTES, 'UTF-8') ?>">下一頁</a>
    <?php else: ?>
        <span class="disabled">下一頁</span>
    <?php endif; ?>
</nav>
