'use client';
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
export function Pagination({ page, perPage, total, onPageChange, onPerPageChange, }) {
    const totalPages = Math.max(1, Math.ceil(total / perPage));
    const start = (page - 1) * perPage + 1;
    const end = Math.min(page * perPage, total);
    function pageNumbers() {
        const pages = [];
        for (let i = 1; i <= totalPages; i++) {
            if (i === 1 || i === totalPages || Math.abs(i - page) <= 1) {
                pages.push(i);
            }
            else if (pages[pages.length - 1] !== 'ellipsis') {
                pages.push('ellipsis');
            }
        }
        return pages;
    }
    return (_jsxs("div", { className: "flex items-center justify-between text-sm", children: [_jsxs("span", { className: "text-[var(--muted-foreground)]", children: [start, "\u2013", end, " of ", total, " results"] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("select", { value: perPage, onChange: (e) => {
                            onPerPageChange(Number(e.target.value));
                            onPageChange(1);
                        }, className: "rounded-md border border-[var(--border)] bg-[var(--input-background)] px-2 py-1 text-sm", children: [10, 25, 50, 100].map((n) => (_jsxs("option", { value: n, children: [n, " / page"] }, n))) }), _jsxs("nav", { className: "flex items-center gap-1", children: [_jsx("button", { onClick: () => onPageChange(page - 1), disabled: page <= 1, className: "rounded-md px-2 py-1 hover:bg-[var(--accent)] disabled:opacity-50", children: "Prev" }), pageNumbers().map((p, i) => p === 'ellipsis' ? (_jsx("span", { className: "px-1 text-[var(--muted-foreground)]", children: "\u2026" }, `e${i}`)) : (_jsx("button", { onClick: () => onPageChange(p), className: `min-w-[2rem] rounded-md px-2 py-1 ${p === page
                                    ? 'bg-[var(--primary)] text-[var(--primary-foreground)]'
                                    : 'hover:bg-[var(--accent)]'}`, children: p }, p))), _jsx("button", { onClick: () => onPageChange(page + 1), disabled: page >= totalPages, className: "rounded-md px-2 py-1 hover:bg-[var(--accent)] disabled:opacity-50", children: "Next" })] })] })] }));
}
//# sourceMappingURL=Pagination.js.map