"use client"; import React from "react"; import { PaginationProps } from "./types"; import { Link } from "@shared/components/link"; import { MaterialIcon } from "@shared/components/material-icon"; const defaultGetPageHref = (page: number) => `?page=${page}`; export const Pagination: React.FC = ({ currentPage, totalPages, onPageChange, getPageHref = defaultGetPageHref, ariaLabel = "Pagination", }: PaginationProps) => { const pageItems = buildPageItems(currentPage, totalPages); const navLinkBase = "inline-flex items-center justify-center w-9 h-9 rounded-full bg-transparent cursor-pointer transition-colors duration-150 hover:border-text-brand hover:text-text-brand"; const navLinkDisabled = "opacity-40 pointer-events-none"; const pageLinkBase = "inline-flex items-center justify-center w-9 h-9 rounded-lg text-body2 text-gray-700 bg-transparent border-none cursor-pointer transition-colors duration-150 hover:bg-gray-100 hover:text-gray-900"; const pageLinkActive = "bg-bg-surface-active font-bold hover:bg-bg-gray-300"; return ( ); }; /** Returns an array of page numbers and ellipsis to render. */ function buildPageItems(current: number, total: number): (number | "...")[] { if (total <= 7) { return Array.from({ length: total }, (_, i) => i + 1); } if (current <= 4) { return [1, 2, 3, 4, 5, "...", total]; } if (current >= total - 3) { return [1, "...", total - 4, total - 3, total - 2, total - 1, total]; } return [1, "...", current - 1, current, current + 1, "...", total]; }