"use client"; import { useEffect, useState } from "react"; import { api } from "@/lib/api"; import { buildKpis } from "@/lib/overview"; import { ValuationCard } from "@/components/prism/ValuationCard"; import { KPIStrip } from "@/components/prism/KPIStrip"; import { TickerHeader } from "@/components/prism/TickerHeader"; import type { TickerOverview, ValuationResponse } from "@/types/api"; type ValState = "loading" | "ready" | "error"; type Props = { ticker: string; overview: TickerOverview; isSaved: boolean; onToggleWatchlist: () => void; }; export function ValuationPage({ ticker, overview, isSaved, onToggleWatchlist }: Props) { const [data, setData] = useState(null); const [valState, setValState] = useState("loading"); const kpis = buildKpis(overview); useEffect(() => { let cancelled = false; setValState("loading"); setData(null); api .valuation(ticker) .then((res) => { if (!cancelled) { setData(res); setValState("ready"); } }) .catch(() => { if (!cancelled) setValState("error"); }); return () => { cancelled = true; }; }, [ticker]); return ( <> {valState === "loading" && (
)} {valState === "error" && (

Valuation data unavailable for {ticker}.

)} {valState === "ready" && data && } ); }