import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact'; import { Group } from '@mantine/core'; import { useForm } from '@mantine/form'; import { useDisclosure } from '@mantine/hooks'; import { MutableRefObject } from 'react'; import { RiHashtag } from 'react-icons/ri'; import { Button } from '/@/renderer/components/button'; import { MotionFlex } from '../motion'; import { NumberInput } from '/@/renderer/components/input'; import { Pagination } from '/@/renderer/components/pagination'; import { Popover } from '/@/renderer/components/popover'; import { Text } from '/@/renderer/components/text'; import { useContainerQuery } from '/@/renderer/hooks'; import { TablePagination as TablePaginationType } from '/@/renderer/types'; interface TablePaginationProps { id?: string; pagination: TablePaginationType; setIdPagination?: (id: string, pagination: Partial) => void; setPagination?: (pagination: Partial) => void; tableRef: MutableRefObject; } export const TablePagination = ({ id, tableRef, pagination, setPagination, setIdPagination, }: TablePaginationProps) => { const [isGoToPageOpen, handlers] = useDisclosure(false); const containerQuery = useContainerQuery(); const goToForm = useForm({ initialValues: { pageNumber: undefined, }, }); const handlePagination = (index: number) => { const newPage = index - 1; tableRef.current?.api.paginationGoToPage(newPage); setPagination?.({ currentPage: newPage }); setIdPagination?.(id || '', { currentPage: newPage }); }; const handleGoSubmit = goToForm.onSubmit((values) => { handlers.close(); if (!values.pageNumber || values.pageNumber < 1 || values.pageNumber > pagination.totalPages) { return; } const newPage = values.pageNumber - 1; tableRef.current?.api.paginationGoToPage(newPage); setPagination?.({ currentPage: newPage }); setIdPagination?.(id || '', { currentPage: newPage }); }); const currentPageStartIndex = pagination.currentPage * pagination.itemsPerPage + 1; const currentPageMaxIndex = (pagination.currentPage + 1) * pagination.itemsPerPage; const currentPageStopIndex = currentPageMaxIndex > pagination.totalItems ? pagination.totalItems : currentPageMaxIndex; return ( {containerQuery.isMd ? ( <> Showing {currentPageStartIndex} - {currentPageStopIndex} of{' '} {pagination.totalItems} items ) : containerQuery.isSm ? ( <> {currentPageStartIndex} - {currentPageStopIndex} of{' '} {pagination.totalItems} items ) : ( <> {currentPageStartIndex} - {currentPageStopIndex} of{' '} {pagination.totalItems} )} handlers.close()} >
); };