import type { Overview } from "../lib/overview";
import { ago, perHour, yen } from "../lib/format";
import { host } from "../lib/agent";
import { Button, Panel, Pill, Row, RowName, ScreenHead } from "../components/ui";
export function Nodes({ ov }: { ov: Overview | null }) {
return (
<>
<ScreenHead title="Nodes" sub={ov ? `${ov.nodesOnline} of ${ov.nodesTotal} online` : undefined} />
<Panel title="Your nodes" aside="budget and backend per node arrive with agent API v2">
{ov?.nodes?.length ? (
ov.nodes.map((n) => (
<Row key={n.id} cols="1fr auto auto auto">
<RowName name={n.thisNode ? `${n.name} (this node)` : n.name} sub={`${n.workers} workers ยท seen ${ago(n.lastSeenAt)}`} />
<Pill tone={n.online ? "ok" : "neutral"}>{n.online ? "Online" : n.freshness}</Pill>
<span className="tnum text-right font-semibold">
{n.priceMin === null ? "โ" : n.priceMin === n.priceMax ? perHour(n.priceMin) : `${yen(n.priceMin)}โ${perHour(n.priceMax)}`}
</span>
<Button size="sm" disabled={!n.link} onClick={() => n.link && host.openExternal(n.link)}>
Hub โ
</Button>
</Row>
))
) : (
<span className="text-[12px] text-fg-dim">{ov ? "No nodes reported by the hub yet." : "Waiting for the agent."}</span>
)}
</Panel>
</>
);
}