'use client'; import { useColumnsResolver, useIsMobile } from '@/hooks'; import { Table as $Table, Switch, TableScrollContainer, TableTbody, TableTd, TableTh, TableThead, TableTr, } from '@mantine/core'; import { flexRender, getCoreRowModel, useReactTable, } from '@tanstack/react-table'; import { useTableStore } from '@/store'; import { useTranslations } from 'next-intl'; type Props = { data: T[]; colsSet: ColsSet; }; export const Table = ({ data, colsSet }: Props) => { const columns = useColumnsResolver(colsSet); const table = useReactTable({ columns, data, getCoreRowModel: getCoreRowModel(), }); const isMobile = useIsMobile(); const tableStore = useTableStore(); const t = useTranslations(); return ( <> {tableStore.isCards ? ( <>
{table.getCoreRowModel().rows.map((row) => ( <$Table key={row.id} withTableBorder> {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.header, {})} {flexRender( cell.column.columnDef.cell, cell.getContext(), )} ))} ))}
) : ( <$Table striped className="min-w-max"> {table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext(), )} ))} ))} {table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender( cell.column.columnDef.cell, cell.getContext(), )} ))} ))} )}
); };