import { memo, useMemo } from 'react'; import { Handle, Position, type NodeProps } from '@xyflow/react'; import type { Module } from '../../../types'; import { MODULE_TYPE_COLORS, MODULE_TYPE_LABELS } from '../../../lib/constants'; import { Badge } from '../../ui/Badge'; export interface DeviceNodeData { label: string; module?: Module; [key: string]: unknown; } export const DeviceNode = memo(({ data, selected }: NodeProps) => { const nodeData = data as DeviceNodeData; const mod = nodeData.module; const colors = mod ? MODULE_TYPE_COLORS[mod.type] : null; const meta = useMemo(() => { try { return nodeData.metadata ? JSON.parse(nodeData.metadata as string) : {}; } catch { return {}; } }, [nodeData.metadata]); const ipToDisplay = meta.ipAddress || mod?.ipAddress; const hasAddress = ipToDisplay || meta.port; return (
{/* Colored accent strip */} {colors &&
}
{nodeData.label}
{mod && (
{MODULE_TYPE_LABELS[mod.type]} {hasAddress && ( {ipToDisplay}{meta.port ? `:${meta.port}` : ''} )}
)} {!mod && (
Unlinked device {hasAddress && ( {ipToDisplay}{meta.port ? `:${meta.port}` : ''} )}
)}
); }); DeviceNode.displayName = 'DeviceNode';