/**
 * The listing pager.
 *
 * Every page number, as the Blade component prints them — not just prev/next.
 * The URLs come from the backend with `?page=1` already stripped from the link
 * back to the start: the controller answers that URL with a 301 to the bare one,
 * so a "1" that kept the parameter would point at a redirect, and a crawler
 * reads that as a redirecting target advertised by rel="prev".
 */
export default function Pagination({ pagination, label }: { pagination: any; label: string }) {
  if (!pagination?.hasPages) {
    return null;
  }

  return (
    <nav className="pagination" aria-label={label}>
      {pagination.links.map((link: any) =>
        link.current ? (
          <span className="current" aria-current="page" key={link.page}>
            {link.page}
          </span>
        ) : (
          <a href={link.url ?? undefined} key={link.page}>
            {link.page}
          </a>
        ),
      )}
    </nav>
  );
}
