'use client' import { useTranslations } from 'next-intl' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table' import { ArrowLeft, ArrowRight, AlertTriangle, Calendar, TrendingUp, TrendingDown, FileText, } from 'lucide-react' import { formatCurrency } from '@/lib/utils' import { summarizeByCurrency } from '@/lib/import/bank-file/currency-summary' import type { BankFileParseResult, BankFileDuplicateInfo } from '@/lib/import/bank-file/types' interface BankFilePreviewStepProps { parseResult: BankFileParseResult duplicateInfo?: BankFileDuplicateInfo | null onContinue: () => void onBack: () => void } export default function BankFilePreviewStep({ parseResult, duplicateInfo, onContinue, onBack, }: BankFilePreviewStepProps) { const t = useTranslations('transactions') const { transactions, stats, issues, date_from, date_to } = parseResult const errors = issues.filter((i) => i.severity === 'error') const hasIssues = errors.length > 0 const warnings = issues.filter((i) => i.severity === 'warning') // Wise/camt.053 files can mix currencies per row: the parser-level totals // sum across currencies, so income/expenses are grouped per currency here. const currencyTotals = summarizeByCurrency(transactions) const duplicateCount = duplicateInfo?.duplicate_count ?? 0 // Table rows render transactions.slice(0, 50), so the slice index IS the // original array index the server flagged. const duplicateRowSet = new Set(duplicateInfo?.duplicate_row_indexes ?? []) return (
{stats.parsed_rows}
{stats.skipped_rows > 0 && ({stats.skipped_rows} rader hoppades över
)}{date_from || '-'} till {date_to || '-'}
{formatCurrency(row.total_income, row.currency)}
))}{formatCurrency(row.total_expenses, row.currency)}
))}{t('import_duplicate_rows_body')}
Rad {issue.row}: {issue.message}
))} {warnings.length > 10 && (...och {warnings.length - 10} till
)}Visar 50 av {transactions.length} transaktioner
)}Filen innehåller fel som förhindrar import
Rad {issue.row}: {issue.message}
))}