"use client"; import type { FinancialRow, FinancialsResponse } from "@/types/api"; import { fmtLarge } from "@/lib/format"; type StatementKey = "income" | "balance" | "cash_flow"; type PeriodKey = "annual" | "quarterly"; type Props = { data: FinancialsResponse; statement: StatementKey; period: PeriodKey; onChangeStatement: (s: StatementKey) => void; onChangePeriod: (p: PeriodKey) => void; }; const STMT_LABELS: Record = { income: "INCOME", balance: "BALANCE", cash_flow: "CASH FLOW", }; function fmtFinVal(val: number | null | undefined, isMargin: boolean): string { if (val === null || val === undefined) return "—"; if (isMargin) return `${(val * 100).toFixed(1)}%`; return fmtLarge(val); } function FinRow({ row, lastColIdx }: { row: FinancialRow; lastColIdx: number }) { if (row.is_section) { return ( {row.label} ); } const cls = [ "psm-fin-row", row.is_total ? "is-total" : "", row.is_margin ? "is-margin" : "", row.indent === 1 ? "is-indent" : "", ] .filter(Boolean) .join(" "); return ( {row.label} {row.values.map((val, i) => ( {fmtFinVal(val, row.is_margin)} ))} ); } export function FinancialsCard({ data, statement, period, onChangeStatement, onChangePeriod, }: Props) { const stmt = data[statement]; const lastColIdx = stmt.columns.length - 1; return (
{(["income", "balance", "cash_flow"] as StatementKey[]).map((key) => ( ))}
{(["annual", "quarterly"] as PeriodKey[]).map((p) => ( ))}
{stmt.columns.length === 0 ? (

Statement data unavailable.

) : (
{stmt.columns.map((col, i) => ( ))} {stmt.rows.map((row, i) => ( ))}
USD (millions) {col}
)}
); }