import { ColumnDef, flexRender, } from "@tanstack/react-table" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@marzneshin/components" import { useTranslation } from "react-i18next" import { useEntityTableContext } from "./entity-table-provider" import { LoaderCircle } from "lucide-react" interface DataTableProps { columns: ColumnDef[] onRowClick?: (object: TData) => void } export function EntityDataTable({ columns, onRowClick, }: DataTableProps) { const { t } = useTranslation(); const { table, isLoading } = useEntityTableContext() return ( {table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { return ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext() )} ) })} ))} {isLoading ? ( ) : ( table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( onRowClick && onRowClick(row.original)} > {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( {t('table.no-result')} ) )}
) }