import { Skeleton } from "@repo/shadcn-ui/components/skeleton"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@repo/shadcn-ui/components/table"; import type { ReactNode } from "react"; import { useRef } from "react"; import { hasCellContent } from "../lib/collection-cell-content"; import type { EntityListState } from "../lib/entity-list-state"; import { EntityListStatus } from "./entity-list-status"; export type CompactColumn = { id: string; label: string; render: (item: T) => ReactNode; align?: "start" | "end"; }; /** Comparación contextual sin herramientas de exploración ni estado remoto propio. */ export function CompactTable({ title, className, items, columns, emptyMessage, state, onRetry, retryLabel, }: { title: string; className?: string; items: readonly T[]; columns: readonly CompactColumn[]; emptyMessage: string; state?: EntityListState; onRetry?: () => Promise; retryLabel?: string; }) { const ref = useRef(null); const available = state?.status !== "loading" && state?.status !== "unavailable"; return (
{state && ( ref.current} retryLabel={retryLabel ?? ""} state={state} /> )} {columns.map((column) => ( {column.label} ))} {state?.status === "loading" && ( )} {available && items.map((item) => ( {columns.map((column) => ( {cellContent(column.render(item))} ))} ))} {available && items.length === 0 && ( {emptyMessage} )}
); } function cellContent(content: ReactNode) { return hasCellContent(content) ? content : "—"; }