import React from 'react'; import { Button } from '../Button/Button'; import { Text } from '../Text/Text'; import { useTheme } from '../../core/theme/ThemeProvider'; import { useStyles } from '../../core/hooks/useStyles'; interface PaginationProps { count: number; // total number of pages page: number; // current page (1-based) onChange: (page: number) => void; className?: string; } export const Pagination: React.FC = ({ count, page, onChange, className = '' }) => { const { theme } = useTheme(); const createStyle = useStyles('pagination'); const containerClass = createStyle({ display: 'inline-grid', gridAutoFlow: 'column', alignItems: 'center', gap: theme.spacing.sm, }); const pageButtonClass = createStyle({ minWidth: '36px', height: '36px', padding: '0', borderRadius: '4px', justifyContent: 'center', }); const activePageButtonClass = createStyle({ backgroundColor: theme.colors.primary, color: theme.colors.background, borderColor: theme.colors.primary, '&:hover:not(:disabled)': { backgroundColor: theme.colors.primary, } }); const handlePageChange = (newPage: number) => { if (newPage >= 1 && newPage <= count) { onChange(newPage); } }; const renderPageNumbers = () => { const pageNumbers = []; const maxPagesToShow = 5; let startPage: number, endPage: number; if (count <= maxPagesToShow) { startPage = 1; endPage = count; } else { if (page <= Math.ceil(maxPagesToShow / 2)) { startPage = 1; endPage = maxPagesToShow; } else if (page + Math.floor(maxPagesToShow / 2) >= count) { startPage = count - maxPagesToShow + 1; endPage = count; } else { startPage = page - Math.floor(maxPagesToShow / 2); endPage = page + Math.floor(maxPagesToShow / 2); } } if (startPage > 1) { pageNumbers.push( ); if (startPage > 2) { pageNumbers.push(); } } for (let i = startPage; i <= endPage; i++) { const isActive = i === page; pageNumbers.push( ); } if (endPage < count) { if (endPage < count - 1) { pageNumbers.push(); } pageNumbers.push( ); } return pageNumbers; }; return ( ); }; export default Pagination;