import { useNavigate } from "react-router-dom"; import { useUpgrade } from "../hooks/useUpgrade"; import { CometIcon, RocketIcon, SparkleIcon } from "./icons/Icons"; const TONE_ICON = { limit: RocketIcon, upgrade: SparkleIcon, action: CometIcon }; const TONE_LABEL = { limit: "Fuel check", upgrade: "Unlock", action: "Next mission" }; /** One floating card, bottom right: the most useful next step, or a limit warning. */ export function NudgeDock() { const { nudge, dismissNudge, openUpgrade } = useUpgrade(); const navigate = useNavigate(); if (!nudge) return null; const Icon = TONE_ICON[nudge.tone]; const go = () => { dismissNudge(nudge.id); if (nudge.to) navigate(nudge.to); else openUpgrade(); }; return ( ); } /** Sidebar card: plan, monthly meters and the upgrade button. Collapses to a rocket button. */ /** What is left this period: "12 left", "45 min left" or "Unlimited". */ function fuelLeft(m: { used: number; limit: number; unit: string }): string { if (m.limit < 0) return "Unlimited"; const left = Math.max(m.limit - m.used, 0); return `${Number.isInteger(left) ? left : left.toFixed(1)}${m.unit ? ` ${m.unit}` : ""} left`; } export function FuelGauge({ collapsed }: { collapsed: boolean }) { const { status, openUpgrade } = useUpgrade(); if (!status) return null; const meters = status.meters.filter((m) => m.key !== "sources"); const low = meters.some((m) => m.limit >= 0 && m.pct >= 0.8); if (collapsed) { return status.can_upgrade ? ( ) : null; } return (
{status.plan.name} plan {low && status.can_upgrade && Low fuel}
{meters.map((m) => (
{m.label} = 0 && m.pct >= 0.8 ? " hot" : ""}`}>{fuelLeft(m)}
= 0.8 ? " hot" : ""}`} style={{ width: `${m.limit < 0 ? 4 : Math.max(3, m.pct * 100)}%` }} />
))} {status.can_upgrade && ( )}
); }