"use client"; import { useVirtualizer } from "@tanstack/react-virtual"; import { useRef } from "react"; import { CategorySelectContent } from "@/features/transactions/components/select-items"; import type { SelectOption } from "@/features/transactions/components/types"; import MoneyValues from "@/shared/components/money-values"; import { TransactionTypeBadge } from "@/shared/components/transaction-type-badge"; import { Checkbox } from "@/shared/components/ui/checkbox"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/shared/components/ui/select"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/shared/components/ui/table"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/shared/components/ui/tooltip"; import type { ImportedTransaction } from "@/shared/lib/import/types"; import { formatDate } from "@/shared/utils/date"; export type ReviewRow = ImportedTransaction & { selected: boolean; isDuplicate: boolean; categoryId: string | null; }; interface ReviewTableProps { rows: ReviewRow[]; categoryOptions: SelectOption[]; onToggle: (index: number) => void; onToggleAll: (selected: boolean) => void; onCategoryChange: (index: number, categoryId: string | null) => void; onDescriptionChange: (index: number, description: string) => void; onUndoDuplicate: (index: number) => void; } export function ReviewTable({ rows, categoryOptions, onToggle, onToggleAll, onCategoryChange, onDescriptionChange, onUndoDuplicate, }: ReviewTableProps) { const allSelected = rows.every((r) => r.selected); const someSelected = rows.some((r) => r.selected); const parentRef = useRef(null); const virtualizer = useVirtualizer({ count: rows.length, getScrollElement: () => parentRef.current, estimateSize: () => 44, overscan: 8, }); const virtualRows = virtualizer.getVirtualItems(); const totalSize = virtualizer.getTotalSize(); const paddingTop = virtualRows.length > 0 ? (virtualRows[0]?.start ?? 0) : 0; const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0) : 0; return (
onToggleAll(!!v)} aria-label="Selecionar todas" data-state={ !allSelected && someSelected ? "indeterminate" : undefined } /> Data Descrição Categoria Tipo Valor {paddingTop > 0 && ( )} {virtualRows.map((virtualRow) => { const row = rows[virtualRow.index]; if (!row) { return null; } const index = virtualRow.index; return ( onToggle(index)} aria-label={`Selecionar ${row.description}`} /> {formatDate(row.date)} onDescriptionChange(index, e.target.value) } className="w-full bg-transparent text-sm outline-none focus:rounded focus:ring-1 focus:ring-ring" /> {row.isDuplicate && (
Já importada

Esta transação já foi importada anteriormente.

Remover a importação anterior e marcar para reimportar.

)}
); })} {paddingBottom > 0 && ( )}
); }