import * as React from "react" import { Select } from "@/components/ui/select" import { Pagination, type PaginationLabels } from "@/components/navigation/pagination" import { cn } from "@/lib/utils" export type DataTablePaginationLabels = PaginationLabels & { rowsPerPage?: React.ReactNode pageInfo?: (page: number, pageCount: number, rowCount?: number) => React.ReactNode } export type DataTablePaginationProps = React.ComponentProps<"div"> & { pageIndex: number pageSize: number pageCount?: number rowCount?: number pageSizeOptions?: number[] disabled?: boolean showPageSize?: boolean labels?: DataTablePaginationLabels onPageChange?: (pageIndex: number) => void onPageSizeChange?: (pageSize: number) => void } function getDataTablePageCount(pageSize: number, pageCount?: number, rowCount?: number) { if (typeof pageCount === "number") return Math.max(pageCount, 1) if (typeof rowCount === "number") return Math.max(Math.ceil(rowCount / pageSize), 1) return 1 } function DataTablePagination({ className, pageIndex, pageSize, pageCount, rowCount, pageSizeOptions = [10, 20, 30, 50, 100], disabled = false, showPageSize = true, labels, onPageChange, onPageSizeChange, ...props }: DataTablePaginationProps) { const resolvedPageCount = getDataTablePageCount(pageSize, pageCount, rowCount) const currentPage = Math.min(Math.max(pageIndex + 1, 1), resolvedPageCount) return (
{labels?.pageInfo?.(currentPage, resolvedPageCount, rowCount) ?? `Page ${currentPage} of ${resolvedPageCount}`}
{showPageSize && onPageSizeChange && (
{labels?.rowsPerPage ?? "Rows per page"}