import type { ReactElement } from 'react'
import { useData, usePublish, type PanelRef } from '@jaspers-ai/sdk'
import { display as d } from './format'
import { lineValue, type Frequency, type LineKind, type Statement } from './server/financials'
import { Bar, Empty, Loading, Section, SymbolField, usePanelStateValue, useStateWriter } from './shared'
import { list, record, text } from './values'
import { financialsOutput, readFinancialsState, type FinancialsState } from './views'
import './styles.css'
// One company's statement: line items down, periods across, latest first, the lines that matter in
// bold. The toggles write `statement` and `frequency`; a balance sheet has no trailing twelve months,
// so choosing one while TTM is on moves to annual.
const STATEMENTS: [Statement, string][] = [
['income', 'Income'],
['balance', 'Balance sheet'],
['cashflow', 'Cash flow'],
]
const FREQUENCIES: [Frequency, string][] = [
['annual', 'Annual'],
['quarterly', 'Quarterly'],
['trailing', 'TTM'],
]
export function FinancialsView({ panel }: { panel: PanelRef }): ReactElement {
const state = usePanelStateValue(panel)
const write = useStateWriter(panel)
if (state === undefined) return
| {state.frequency === 'trailing' ? 'Twelve months to' : 'Period ended'} | {periods.map((p) => ({p} | ))}
|---|---|
| {text(row['label'])} | {periods.map((p) => { const value = typeof values[p] === 'number' ? (values[p] as number) : null return ({lineValue(kind, value, d)} | ) })}