import React from "react"; import { __ } from "@wordpress/i18n"; const FirstIcon = () => ( ); const PrevIcon = () => ( ); const NextIcon = () => ( ); const LastIcon = () => ( ); const ChevronDownIcon = () => ( ); /** * Build per-page options dynamically from the total. * Base is always [10, 20, 50], then adds multiples of 100 until the last * option is >= total (so there's always one option that fits everything). * Examples: 70 → [10,20,50,100] | 645 → [10,20,50,100,200,…,700] */ function buildPerPageOptions(total) { const options = [10, 20, 50]; let n = 100; while (options[options.length - 1] < total) { options.push(n); n += 100; } return options; } const buildPageList = (page, totalPages) => { if (totalPages <= 7) { return Array.from({ length: totalPages }, (_, i) => i + 1); } const pages = [1]; if (page > 3) pages.push("…"); for (let i = Math.max(2, page - 1); i <= Math.min(totalPages - 1, page + 1); i++) { pages.push(i); } if (page < totalPages - 2) pages.push("…"); pages.push(totalPages); return pages; }; const Pagination = ({ total, page, perPage, onPageChange, onPerPageChange }) => { const totalPages = Math.ceil(total / perPage); // Hide the whole pagination (info + rows-per-page + nav) on a single page. if (!total || totalPages <= 1) return null; const showNav = totalPages > 1; const perPageOptions = buildPerPageOptions(total); const start = (page - 1) * perPage + 1; const end = Math.min(page * perPage, total); const pageList = buildPageList(page, totalPages); const handlePerPageChange = (e) => { onPerPageChange(Number(e.target.value)); onPageChange(1); }; return (