import type { ReactNode } from 'react' import { ChevronDown, ChevronUp } from 'lucide-react' import { cn } from '@/lib/cn' export type Column = { key: string header: ReactNode render: (row: T) => ReactNode sortable?: boolean width?: string align?: 'left' | 'center' | 'right' } type Props = { columns: Column[] rows: T[] getRowKey: (row: T) => string isLoading?: boolean empty?: ReactNode sortBy?: string sortDesc?: boolean onSortChange?: (sortBy: string, sortDesc: boolean) => void onRowClick?: (row: T) => void } export function DataTable({ columns, rows, getRowKey, isLoading, empty, sortBy, sortDesc, onSortChange, onRowClick, }: Props) { return (
{columns.map(c => ( ))} {isLoading && Array.from({ length: 5 }).map((_, i) => ( {columns.map(c => ( ))} ))} {!isLoading && rows.length === 0 && ( )} {!isLoading && rows.map(row => ( onRowClick?.(row)} > {columns.map(c => ( ))} ))}
{c.sortable && onSortChange ? ( ) : ( c.header )}
{empty ?? 'Không có dữ liệu'}
{c.render(row)}
) } type PaginationProps = { page: number pageSize: number total: number onChange: (page: number) => void } export function Pagination({ page, pageSize, total, onChange }: PaginationProps) { const totalPages = Math.max(1, Math.ceil(total / pageSize)) const from = total === 0 ? 0 : (page - 1) * pageSize + 1 const to = Math.min(page * pageSize, total) return (
{from}–{to} / {total}
Trang {page}/{totalPages}
) }