"use client"; import { Button } from "@suphark/ui/components/shared/button/button"; import { useUiText } from "@suphark/ui/components/shared/ui-text"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@suphark/ui/components/ui/select"; import { cn } from "@suphark/ui/lib/utils"; import type { Table } from "@tanstack/react-table"; import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from "lucide-react"; interface DataTablePaginationProps { table: Table; pageSizeOptions?: number[]; onPageSizeChange?: (pageSize: number) => void; /** `quiet` = "1–10 จาก 128 · แถวต่อหน้า · ‹ 1 / 13 ›" (ตัดปุ่มหน้าแรก/สุดท้ายและข้อความจำนวนที่เลือก) */ variant?: "default" | "quiet"; } export function DataTablePagination({ table, pageSizeOptions = [10, 20, 30, 40, 50], onPageSizeChange, variant = "default", }: DataTablePaginationProps) { const text = useUiText(); if (variant === "quiet") { const { pageIndex, pageSize } = table.getState().pagination; const total = table.options.manualPagination ? (table.options.rowCount ?? table.getRowModel().rows.length) : table.getFilteredRowModel().rows.length; const from = total === 0 ? 0 : pageIndex * pageSize + 1; const to = Math.min(total, (pageIndex + 1) * pageSize); return (
{(text.table?.rangeOf ?? "{from}–{to} จาก {total}") .replace("{from}", String(from)) .replace("{to}", String(to)) .replace("{total}", String(total))}
{text.table?.rowsPerPage ?? "แถวต่อหน้า"}
{pageIndex + 1} / {Math.max(1, table.getPageCount())}
); } const isRowSelectionEnabled = table.options.enableRowSelection !== false; return (
{isRowSelectionEnabled && (
{(text.table?.rowsSelected ?? "เลือก {selected} จาก {total} แถว") .replace("{selected}", String(table.getFilteredSelectedRowModel().rows.length)) .replace("{total}", String(table.getFilteredRowModel().rows.length))}
)}

{text.table?.rowsPerPage ?? "แถวต่อหน้า"}

{(text.table?.pageOf ?? "หน้า {page} จาก {pages}") .replace("{page}", String(table.getState().pagination.pageIndex + 1)) .replace("{pages}", String(Math.max(1, table.getPageCount())))}
); }