<?php
/**
 * Pagination component — with styled links and Lucide arrow icons.
 *
 * @var array $pagination
 * @var string $baseUrl (optional)
 */
$pagination = $pagination ?? [];
if (empty($pagination) || ($pagination['last_page'] ?? 1) <= 1) return;
$baseUrl = $baseUrl ?? '?';
$separator = str_contains($baseUrl, '?') ? '&' : '?';
?>
<nav class="pagination-wrapper">
    <div class="pagination-info">
        عرض <?= $pagination['from'] ?> إلى <?= $pagination['to'] ?> من <?= $pagination['total'] ?> نتيجة
    </div>
    <ul class="pagination">
        <?php if ($pagination['has_prev']): ?>
            <li>
                <a href="<?= $baseUrl . $separator ?>page=<?= $pagination['prev_page'] ?>" class="page-link" title="السابق">
                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>
                </a>
            </li>
        <?php endif; ?>

        <?php foreach ($pagination['pages'] as $page): ?>
            <?php if ($page === '...'): ?>
                <li class="page-ellipsis">...</li>
            <?php else: ?>
                <li>
                    <a href="<?= $baseUrl . $separator ?>page=<?= $page ?>"
                       class="page-link <?= $page === $pagination['current_page'] ? 'active' : '' ?>">
                        <?= $page ?>
                    </a>
                </li>
            <?php endif; ?>
        <?php endforeach; ?>

        <?php if ($pagination['has_next']): ?>
            <li>
                <a href="<?= $baseUrl . $separator ?>page=<?= $pagination['next_page'] ?>" class="page-link" title="التالي">
                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
                </a>
            </li>
        <?php endif; ?>
    </ul>
</nav>
