import { BarChart, DataTable, DocumentShell, KeyValueGrid, Section, type BarDatum, } from '@/lib/pdf/brand-kit'; import { stageLabel } from '@/lib/constants'; import type { RevenueData } from '@/lib/services/report-generators'; export interface RevenueReportPdfProps { portName: string; logoBuffer: Buffer | null; data: RevenueData; dateFrom?: string; dateTo?: string; currency?: string; } const STAGE_ORDER = [ 'open', 'details_sent', 'in_communication', 'eoi_sent', 'eoi_signed', 'deposit_10pct', 'contract_sent', 'contract_signed', 'completed', ]; function fmtAmount(n: number, currency: string): string { return `${currency} ${n.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`; } export function RevenueReportPdf({ portName, logoBuffer, data, dateFrom, dateTo, currency = 'USD', }: RevenueReportPdfProps) { const stages = [ ...STAGE_ORDER.filter((s) => data.stageRevenue[s] !== undefined), ...Object.keys(data.stageRevenue).filter((s) => !STAGE_ORDER.includes(s)), ]; const rows = stages.map((stage) => ({ stage, amount: Number(data.stageRevenue[stage] ?? 0), })); const chartData: BarDatum[] = rows.map((r) => ({ label: stageLabel(r.stage), value: r.amount })); const total = Number(data.totalCompleted); const subtotal = rows.reduce((s, r) => s + r.amount, 0); const meta = dateFrom || dateTo ? `Range: ${dateFrom ?? '—'} → ${dateTo ?? 'today'}` : 'All time'; return (
columns={[ { header: 'Stage', flex: 3, render: (r) => stageLabel(r.stage) }, { header: 'Amount', flex: 2, align: 'right', render: (r) => fmtAmount(r.amount, currency), }, ]} rows={rows} totals={['Total', fmtAmount(subtotal, currency)]} emptyMessage="No revenue data." />
); }