"use client"; import { useState, useMemo } from "react"; import { DataTable } from "@/components/shared/data-table/data-table"; import { createDocColumns } from "./doc-columns"; import { useI18n } from "@/i18n/i18n-context"; import type { Document } from "@/types/knowledge-base"; interface DocTableProps { documents: Document[]; onView?: (document: Document) => void; onDelete?: (document: Document) => void; onViewChunks?: (document: Document) => void; onSelectionChange?: (selectedDocuments: Document[]) => void; } export function DocTable({ documents, onView, onDelete, onViewChunks, onSelectionChange, }: DocTableProps) { const { t } = useI18n(); const [rowSelection, setRowSelection] = useState>({}); const columns = useMemo( () => createDocColumns({ t, onView, onDelete, onViewChunks }), [t, onView, onDelete, onViewChunks], ); const handleRowSelectionChange = ( updater: | Record | ((prev: Record) => Record), ) => { const newSelection = typeof updater === "function" ? updater(rowSelection) : updater; setRowSelection(newSelection); if (onSelectionChange) { const selectedDocs = documents.filter((doc) => newSelection[doc.docId]); onSelectionChange(selectedDocs); } }; return ( row.docId} rowSelection={rowSelection} onRowSelectionChange={handleRowSelectionChange} /> ); }