import { fmtAgo, fmtDuration } from '../format' import type { BudgetSession } from '../types' interface Props { session: BudgetSession } const VERDICT_LABELS: Record = { engaged: 'Billing — you are playing', paused: 'Not billing — paused', not_applicable: 'Not billing — no game running', } const CAUSE_LABELS: Record = { idle: 'no input for longer than the idle grace', focus: 'the game window is not focused', screen_held: 'the screen is locked or held', } function describe(values: string[], labels: Record): string[] { return values.map((value) => labels[value] ?? value) } export function BudgetLiveCard({ session }: Props) { if (!session.available) { return (

Right now

No verdict has been logged yet.

) } return (

Right now

{VERDICT_LABELS[session.state] ?? session.state}

{session.qualifying_count > 0 && (

{session.game_name ? ( <> Assigned game {session.game_name} ·{' '} ) : null} {session.qualifying_count} qualifying processes

)} {session.causes.length > 0 && (

Paused because {describe(session.causes, CAUSE_LABELS).join(', ')}.

)}

{session.idle_seconds !== null && <>Idle {fmtDuration(session.idle_seconds)} · } {session.screen_held !== null && <>Screen held: {session.screen_held ? 'yes' : 'no'} · } {/* The daemon logs on change or a 5-minute heartbeat, so this reading can legitimately be minutes old. Saying so beats implying "now". */} as of {fmtAgo(session.observed_at)}

) }