import type { TickerOverview, ValuationResponse } from "@/types/api"; import { fmtCurrency, fmtLarge, fmtNumber, fmtPct } from "@/lib/format"; type ValState = "idle" | "loading" | "ready" | "error"; type Props = { overview: TickerOverview; valuation: ValuationResponse | null; valState: ValState; }; export function ValuationOverviewCard({ overview, valuation, valState }: Props) { const rows = [ { label: "Market Cap", value: fmtLarge(overview.stats.market_cap), missing: overview.stats.market_cap == null }, { label: "P/E TTM", value: overview.stats.trailing_pe == null ? "-" : `${fmtNumber(overview.stats.trailing_pe)}x`, missing: overview.stats.trailing_pe == null }, { label: "EPS TTM", value: fmtCurrency(overview.stats.trailing_eps), missing: overview.stats.trailing_eps == null }, { label: "P/B", value: overview.ratios.price_to_book == null ? "-" : `${fmtNumber(overview.ratios.price_to_book)}x`, missing: overview.ratios.price_to_book == null }, { label: "P/S", value: overview.ratios.price_to_sales == null ? "-" : `${fmtNumber(overview.ratios.price_to_sales)}x`, missing: overview.ratios.price_to_sales == null }, { label: "EV/Sales", value: overview.ratios.ev_to_sales == null ? "-" : `${fmtNumber(overview.ratios.ev_to_sales)}x`, missing: overview.ratios.ev_to_sales == null }, { label: "EV/EBITDA", value: overview.ratios.ev_to_ebitda == null ? "-" : `${fmtNumber(overview.ratios.ev_to_ebitda)}x`, missing: overview.ratios.ev_to_ebitda == null }, ]; const visible = rows.filter((r) => !r.missing); const dcf = valuation?.dcf; const showDcf = dcf?.available && dcf.intrinsic_value_per_share != null; return (
Valuation

Valuation

{visible.length > 0 && (
{visible.map((row) => (
{row.label} {row.value}
))}
)} {valState === "loading" && ( <>
)} {valState === "ready" && showDcf && dcf && ( <>
DCF Intrinsic Value {fmtCurrency(dcf.intrinsic_value_per_share)}
{dcf.growth_rate_used != null && (
FCF Growth Used {fmtPct(dcf.growth_rate_used)}
)}
)}
); }