import { Download, Trash2 } from "lucide-react"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; /** * BankStatementDocumentTable — WealthX DS (L3 Organism) * * A table for managing bank statement documents inside the Bank Statement tab * of `OpportunityDetailsDrawer`. Renders two instances per opportunity: * one for the main applicant and one for the co-applicant. * * Features: * - Select-all / individual row checkboxes * - "Download All" bulk action (disabled when nothing selected) * - Per-row view (click name), download, and delete actions * - Loading and empty states * * Layer: L3 Organism * * Data source: bank statement documents fetched via `DocumentTypeFilter.GENERATED` */ // --------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------- export interface BankStatementDocument { id: string; /** Display filename shown in the Name column. */ name: string; /** Document type label, e.g. "Bank Statement" or "Property Report". */ type: string; /** ISO date string or pre-formatted date label. */ updatedDate: string; /** When true, download / delete action buttons are shown for this row. */ hasDownload: boolean; /** * Whether the underlying PDF data is ready to view/download. * `false` or `undefined` → action buttons are shown but disabled. * `true` → clicking the name triggers `onView`; action buttons are enabled. */ statementReady?: boolean; } export interface BankStatementDocumentTableProps { /** Section heading rendered above the table (e.g. "Main Applicant"). */ title: string; documents: BankStatementDocument[]; /** IDs of currently selected rows. */ selectedIds: string[]; /** Toggle a single row's selection. */ onToggle: (id: string) => void; /** Toggle all rows (select all / deselect all). */ onToggleAll: () => void; /** Bulk download — only enabled when `selectedIds.length > 0`. */ onDownloadAll: () => void; /** Open the PDF viewer for this document (requires `statementReady`). */ onView: (doc: BankStatementDocument) => void; /** Download a single document (requires `statementReady`). */ onDownload: (doc: BankStatementDocument) => void; /** Open the delete confirmation for a document (requires `statementReady`). */ onDelete: (doc: BankStatementDocument) => void; /** Show a loading row instead of documents. */ isLoading?: boolean; /** Disable delete buttons while a deletion is in flight. */ isDeleting?: boolean; className?: string; } // --------------------------------------------------------------------------- // BankStatementDocumentTable // --------------------------------------------------------------------------- export function BankStatementDocumentTable({ title, documents, selectedIds, onToggle, onToggleAll, onDownloadAll, onView, onDownload, onDelete, isLoading = false, isDeleting = false, className, }: BankStatementDocumentTableProps) { const areAllSelected = documents.length > 0 && selectedIds.length === documents.length; const isIndeterminate = selectedIds.length > 0 && !areAllSelected; return (
{/* ── Header ── */}

{title}

{/* ── Table ── */} Name Type Date Action {isLoading ? (

Loading documents…

) : documents.length === 0 ? (

No documents found

) : ( documents.map((doc) => ( onToggle(doc.id)} aria-label={`Select ${doc.name}`} /> {/* Name — clickable when download is ready */}

{ if (doc.hasDownload && doc.statementReady) { onView(doc); } }} > {doc.name}

{doc.type} {doc.updatedDate} {/* Actions */}
{doc.hasDownload && ( <> )}
)) )}
); }