"use client" /** * The service card — the one node the canvas renders for every service. Layered * and elevated (z-depth shadow + hover lift + selected ring), it reads * glanceably: a status accent bar, an icon tile, the service name, its type + * `/v1` capability, its source ref, and a footer with replicas, latest-deploy * relative time, and a metric sparkline preview. Pure presentation — it takes a * `ServiceNodeData` and callbacks; it never fetches. Usable inside the canvas * (via `canvas-node`) or standalone in a grid/list. */ import type { ReactNode } from "react" import { Text, XStack, YStack } from "@hanzo/gui" import { kindLabel, withAlpha } from "./color" import { kindGlyph } from "./glyphs" import { MetricSparkline } from "./MetricSparkline" import { ReplicaPill } from "./ReplicaPill" import { ServiceStatusBadge } from "./ServiceStatusBadge" import { SourceRef } from "./SourceRef" import { statusColors } from "./status" import { relativeTime } from "./time" import type { ServiceNodeData, ServiceStatus, StatusPalette } from "./types" const MONO = "ui-monospace, SFMono-Regular, Menlo, monospace" export interface ServiceNodeProps { data: ServiceNodeData selected?: boolean reducedMotion?: boolean width?: number statusPalette?: Partial> /** Override the icon (e.g. pass a lucide icon); default is the built-in glyph. */ renderIcon?: (data: ServiceNodeData) => ReactNode onOpen?: (data: ServiceNodeData) => void /** `now` for deterministic relative-time rendering (tests/SSR). */ now?: number } export function ServiceNode({ data, selected, reducedMotion, width = 268, statusPalette, renderIcon, onOpen, now, }: ServiceNodeProps) { const c = statusColors(data.status, statusPalette) const accent = data.accent ?? c.dot const tinted = !!data.accent const Glyph = kindGlyph(data.kind) const icon = renderIcon ? renderIcon(data) : const deployed = relativeTime(data.deployedAt, now) return ( onOpen(data) : undefined} hoverStyle={onOpen ? { borderColor: "$color7" } : undefined} > {/* Status accent bar */} {/* Header: icon + name/type + status */} {icon} {data.name} {data.typeLabel ?? kindLabel(data.kind)} {data.capability ? ( {data.capability.path ?? `/v1/${data.capability.id}`} ) : null} {/* Source */} {data.source ? : null} {/* Footer: replicas + deploy time | metric preview */} {data.deployedAt ? ( {deployed} ) : null} {data.metric ? ( {data.metric.value ? ( {data.metric.value} ) : null} ) : null} ) }