import type { ReactNode } from "react"; import { Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, } from "@mui/material"; import { TableEmptyRow, TableLoadingRow } from "@/components/ui/table-state-rows"; export type SortDirection = "asc" | "desc" | ""; export type ResourceListColumn = { id: string; header: ReactNode; render: (row: T) => ReactNode; sortable?: boolean; headerClassName?: string; cellClassName?: string; align?: "left" | "center" | "right"; }; type ResourceListTableProps = { columns: ResourceListColumn[]; rows: T[]; rowKey: (row: T) => string; isLoading: boolean; emptyMessage?: string; sort?: { column: string; direction: SortDirection }; onSort?: (column: string) => void; size?: "small" | "medium"; }; function sortIndicator(direction: SortDirection): string { if (direction === "desc") { return " ↓"; } if (direction === "asc") { return " ↑"; } return ""; } export function ResourceListTable({ columns, rows, rowKey, isLoading, emptyMessage, sort, onSort, size = "small", }: ResourceListTableProps) { const colSpan = columns.length; return ( {columns.map((column) => ( onSort(column.id) : undefined} > {column.header} {column.sortable && sort?.column === column.id ? sortIndicator(sort.direction) : ""} ))} {isLoading ? ( ) : rows.length === 0 ? ( ) : ( rows.map((row) => ( {columns.map((column) => ( {column.render(row)} ))} )) )}
); }