'use client' import { useState } from 'react' import { useTranslations } from 'next-intl' import { Card, CardContent, 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, FileText, Scale } from 'lucide-react' import { formatCurrency, cn } from '@/lib/utils' import type { SkattekontoFileParseResult } from '@/lib/import/skattekonto-file/types' interface SkattekontoFilePreviewStepProps { parseResult: SkattekontoFileParseResult duplicateIndexes: number[] promotionIndexes: number[] orgNumberMismatch: boolean isLoading: boolean onExecute: () => void onBack: () => void } const PREVIEW_ROW_LIMIT = 100 export default function SkattekontoFilePreviewStep({ parseResult, duplicateIndexes, promotionIndexes, orgNumberMismatch, isLoading, onExecute, onBack, }: SkattekontoFilePreviewStepProps) { const t = useTranslations('import') const [mismatchConfirmed, setMismatchConfirmed] = useState(false) const { rows, stats, issues, date_from, date_to, closing_saldo } = parseResult const duplicateSet = new Set(duplicateIndexes) const promotionSet = new Set(promotionIndexes) const newCount = rows.length - duplicateIndexes.length const warnings = issues.filter((i) => i.severity !== 'error') const importBlocked = orgNumberMismatch && !mismatchConfirmed return (
{stats.parsed_rows}
{stats.skipped_rows > 0 && ({t('skattekonto_preview_skipped', { count: stats.skipped_rows })}
)}{date_from || '-'} – {date_to || '-'}
{closing_saldo !== null ? formatCurrency(closing_saldo) : '-'}
{t('skattekonto_org_mismatch_body', { orgNumber: parseResult.org_number ?? '?', companyName: parseResult.company_name ?? '?', })}
{t('skattekonto_duplicates_note', { count: duplicateIndexes.length })}
)} {warnings.length > 0 && ({issue.row > 0 ? `${t('skattekonto_issue_row', { row: issue.row })}: ` : ''} {issue.message}
))}{t('skattekonto_preview_truncated', { shown: PREVIEW_ROW_LIMIT, total: rows.length, })}
)}