<?php if (isset($pagination) && $pagination->total > 0): ?>
<div class="mt-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
    <div class="flex items-center gap-3 text-xs text-gray-500">
        <span><?= number_format($pagination->total) ?> total</span>
        <span class="text-gray-300">|</span>
        <span>Page <?= $pagination->page ?> of <?= $pagination->totalPages ?></span>
        <span class="text-gray-300">|</span>
        <label class="inline-flex items-center gap-1.5">
            Show
            <select onchange="var u=new URL(window.location);u.searchParams.set('per_page',this.value);u.searchParams.delete('page');window.location=u" class="border border-gray-300 rounded px-1.5 py-0.5 text-xs bg-white focus:ring-1 focus:ring-primary-500 focus:border-primary-500">
                <?php foreach ([20, 50, 100, 200, 500, 1000] as $opt): ?>
                    <option value="<?= $opt ?>" <?= $pagination->perPage === $opt ? 'selected' : '' ?>><?= $opt ?></option>
                <?php endforeach; ?>
            </select>
            per page
        </label>
    </div>

    <?php if ($pagination->totalPages > 1): ?>
    <div class="flex items-center gap-1 flex-wrap">
        <?php if ($pagination->hasPrev()): ?>
            <a href="<?= htmlspecialchars($pagination->prevUrl()) ?>" class="inline-flex items-center px-2.5 py-1 text-xs font-medium rounded border bg-white text-gray-600 border-gray-300 hover:bg-gray-50">Prev</a>
        <?php endif; ?>

        <?php foreach ($pagination->pages() as $pg): ?>
            <?php if ($pg === '...'): ?>
                <span class="px-2 py-1 text-xs text-gray-400">...</span>
            <?php elseif ($pg == $pagination->page): ?>
                <span class="inline-flex items-center px-2.5 py-1 text-xs font-medium rounded border bg-primary-600 text-white border-primary-600"><?= (int)$pg ?></span>
            <?php else: ?>
                <a href="?<?= http_build_query(array_merge($_GET, ['page' => $pg])) ?>" class="inline-flex items-center px-2.5 py-1 text-xs font-medium rounded border bg-white text-gray-600 border-gray-300 hover:bg-gray-50"><?= (int)$pg ?></a>
            <?php endif; ?>
        <?php endforeach; ?>

        <?php if ($pagination->hasNext()): ?>
            <a href="<?= htmlspecialchars($pagination->nextUrl()) ?>" class="inline-flex items-center px-2.5 py-1 text-xs font-medium rounded border bg-white text-gray-600 border-gray-300 hover:bg-gray-50">Next</a>
        <?php endif; ?>
    </div>
    <?php endif; ?>
</div>
<?php endif; ?>
