'use client' import Link from 'next/link' import { useTranslations } from 'next-intl' import { Badge } from '@/components/ui/badge' import JournalEntryStatusBadge from '@/components/bookkeeping/JournalEntryStatusBadge' import { formatDate, formatCurrency, cn } from '@/lib/utils' import { formatVoucher } from '@/lib/bookkeeping/voucher-series-resolver' import type { JournalEntry, JournalEntryLine } from '@/types' interface Props { currentEntryId: string chain: JournalEntry[] } function useGetRole() { const t = useTranslations('journal_correction') return (entry: JournalEntry): string => { if (entry.source_type === 'storno') return t('role_storno') if (entry.source_type === 'correction') return t('role_correction') return t('role_original') } } function getTotal(entry: JournalEntry): number { const lines = (entry.lines || []) as JournalEntryLine[] return lines.reduce((sum, l) => sum + (Number(l.debit_amount) || 0), 0) } /** * The storno/rättelse chain as a flat chronological list: one hairline row * per verifikat (role, voucher, date, description, amount). The page owns the * kicker and puts the explanatory copy behind its "?" (convention 7), so this * renders no heading and no info box of its own. */ export default function CorrectionChain({ currentEntryId, chain }: Props) { const t = useTranslations('journal_correction') const getRole = useGetRole() if (chain.length === 0) return null // Combine current entry isn't in chain: chain is "other" entries // Sort chronologically const sorted = [...chain].sort( (a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime() ) return ( ) }