import { flipIconStyles, getCommonTooltipProps, parseFromValuesOrFunc } from "@/core/utils/utils"; import { useTheme } from "@emotion/react"; import { Box, IconButton, InputLabel, MenuItem, Pagination, PaginationItem, Select, Tooltip, Typography, useMediaQuery, } from "@mui/material"; const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100]; const DataTable_TablePagination = ({ position = "bottom", table, ...rest }) => { const theme = useTheme(); const isMobile = useMediaQuery("(max-width: 720px)"); const { getState, options: { enableToolbarInternalActions, icons: { ChevronLeftIcon, ChevronRightIcon, FirstPageIcon, LastPageIcon }, localization, muiPaginationProps, paginationDisplayMode, }, } = table; const { pagination: { pageIndex = 0, pageSize = 10 }, showGlobalFilter, } = getState(); const paginationProps = { ...parseFromValuesOrFunc(muiPaginationProps, { table, }), ...rest, }; const totalRowCount = table.getRowCount(); const numberOfPages = table.getPageCount(); const showFirstLastPageButtons = numberOfPages > 2; const firstRowIndex = pageIndex * pageSize; const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount); const { SelectProps = {}, disabled = false, rowsPerPageOptions = defaultRowsPerPage, showFirstButton = showFirstLastPageButtons, showLastButton = showFirstLastPageButtons, showRowsPerPage = true, ...restPaginationProps } = paginationProps ?? {}; const disableBack = pageIndex <= 0 || disabled; const disableNext = lastRowIndex >= totalRowCount || disabled; if (isMobile && SelectProps?.native !== false) { SelectProps.native = true; } const tooltipProps = getCommonTooltipProps(); return ( {showRowsPerPage && ( {localization.rowsPerPage} )} {paginationDisplayMode === "pages" ? ( table.setPageIndex(newPageIndex - 1)} page={pageIndex + 1} renderItem={(item) => ( )} showFirstButton={showFirstButton} showLastButton={showLastButton} {...restPaginationProps} /> ) : paginationDisplayMode === "default" ? ( <> {`${ lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString() }-${lastRowIndex.toLocaleString()} ${ localization.of } ${totalRowCount.toLocaleString()}`} {showFirstButton && ( table.firstPage()} size="small" > )} table.previousPage()} size="small" > table.nextPage()} size="small" > {showLastButton && ( table.lastPage()} size="small" > )} ) : null} ); }; export default DataTable_TablePagination;