'use client' import { ArrowDown, AlertTriangle } from 'lucide-react' import { formatCurrency, formatDate } from '@/lib/utils' import { DocumentViewButton } from './DocumentViewButton' interface AttachDocumentPreviewProps { data: Record params: Record } /** * Two-card preview for `attach_document_to_transaction` operations. Renders * the transaction and the document side by side so the reviewer can confirm * the pairing without cross-referencing IDs. */ export function AttachDocumentPreview({ data, params }: AttachDocumentPreviewProps) { const txDescription = (data.transaction_description as string) || '-' const txAmount = data.transaction_amount as number | undefined const txCurrency = (data.transaction_currency as string) || 'SEK' const txDate = data.transaction_date as string | undefined const docFileName = (data.document_file_name as string) || '-' const docVendor = data.document_vendor_name as string | undefined const docAmount = data.document_amount as number | undefined const docCurrency = (data.document_currency as string) || txCurrency const docInvoiceDate = data.document_invoice_date as string | undefined const willOverwrite = data.will_overwrite_existing === true const existingDocName = data.existing_document_file_name as string | undefined // Fail safe: if the staging tool didn't explicitly assert the existing doc // is NOT räkenskapsinformation (i.e. `=== false`), treat overwrite as a // BFL 7 kap event. A missing/undefined flag must not silently downgrade // the destructive warning. const existingIsAccounting = willOverwrite && data.existing_document_is_rakenskapsinformation !== false const documentId = params.document_id as string | undefined return (
{docVendor && } {docInvoiceDate && } {typeof docAmount === 'number' && ( )} {documentId && (
)}
kopplas till transaktionen
{willOverwrite && existingIsAccounting && (

Ersätter räkenskapsinformation

Befintligt dokument{existingDocName ? ` (${existingDocName})` : ''} är markerat som räkenskapsinformation enligt BFL 7 kap. Att ersätta det här gör det tidigare verifikationsunderlaget otillgängligt: bekräfta att du har originalet sparat innan du godkänner.

)} {willOverwrite && !existingIsAccounting && (
Ersätter befintligt dokument{existingDocName ? `: ${existingDocName}` : ''}.
)}
) } function PreviewCard({ label, children }: { label: string; children: React.ReactNode }) { return (

{label}

{children}
) } function Row({ label, value, tabular }: { label: string; value: string; tabular?: boolean }) { return (
{label} {value}
) }