'use client' import { useTranslations } from 'next-intl' import { Button } from '@/components/ui/button' import { TH_CLASS, TD_CLASS, QUIET_LINK_CLASS } from '@/components/ui/dry-table' import { cn, formatCurrency, formatDate } from '@/lib/utils' import { formatVoucher } from '@/lib/bookkeeping/voucher-series-resolver' /** * The automatic matcher's dry-run preview, inline on the Avstämning page: * candidate transaction↔verifikat pairs with confidence, applied per row or * all strong ones at once. Same endpoint and same server-side intersection * guard as the old bank view; this is only the surface. Pairs at or above * STRONG_CONFIDENCE mirror the old view's preselect floor. */ export const STRONG_CONFIDENCE = 0.85 export interface MatcherMatch { transaction_id: string transaction_date: string transaction_description: string transaction_amount: number journal_entry_id: string voucher_number: number voucher_series: string entry_date: string entry_description: string method: string confidence: number } interface MatcherPreviewProps { matches: MatcherMatch[] currency: string busy: boolean onApply: (pairs: MatcherMatch[], strongOnly: boolean) => void onClose: () => void } export function MatcherPreview({ matches, currency, busy, onApply, onClose }: MatcherPreviewProps) { const t = useTranslations('reconciliation') const strong = matches.filter((m) => m.confidence >= STRONG_CONFIDENCE) if (matches.length === 0) { return (

{t('matcher_none')}{' '}

) } return (

{t('matcher_title', { count: matches.length })}

{strong.length > 0 && ( )}
{matches.map((m) => ( ))}
{t('col_date')} {t('col_event')} {t('col_amount')} {t('col_proposal')}
{formatDate(m.transaction_date)} {m.transaction_description} {formatCurrency(m.transaction_amount, currency)} {formatVoucher({ voucher_series: m.voucher_series, voucher_number: m.voucher_number })} {formatDate(m.entry_date)} = STRONG_CONFIDENCE ? 'bg-success/10 text-success' : 'bg-muted text-muted-foreground', )} > {m.confidence >= STRONG_CONFIDENCE ? t('matcher_strong') : t('confidence', { percent: Math.round(m.confidence * 100) })} {m.entry_description}
) }