"use client" import { memo, useEffect } from "react" import type { ViewportGraphNode, ViewportDocument, ViewportMemoryEntry } from "@/lib/viewport-graph-types" import { FileText, Calendar, Hash, ExternalLink, X, Brain } from "lucide-react" export interface NodePopoverProps { node: ViewportGraphNode x: number y: number onClose: () => void containerBounds?: DOMRect } export const NodePopover = memo(function NodePopover({ node, x, y, onClose, containerBounds, }) { useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") { onClose() } } window.addEventListener("keydown", handleKeyDown) return () => window.removeEventListener("keydown", handleKeyDown) }, [onClose]) const backdropStyle = containerBounds ? { left: `${containerBounds.left}px`, top: `${containerBounds.top}px`, width: `${containerBounds.width}px`, height: `${containerBounds.height}px`, } : undefined const isMemory = node.type === "memory" const doc = isMemory ? null : (node.data as ViewportDocument) const memory = isMemory ? (node.data as ViewportMemoryEntry) : null const getDocumentUrl = () => { if (!doc) return undefined if (doc.type === "google_doc" && doc.customId) { return `https://docs.google.com/document/d/${doc.customId}` } if (doc.type === "google_sheet" && doc.customId) { return `https://docs.google.com/spreadsheets/d/${doc.customId}` } if (doc.type === "google_slide" && doc.customId) { return `https://docs.google.com/presentation/d/${doc.customId}` } return doc.url ?? undefined } const documentUrl = getDocumentUrl() const title = doc?.title ?? memory?.title ?? "Untitled" const summary = doc?.summary ?? memory?.summary ?? memory?.content const type = doc?.type ?? memory?.type ?? "Memory" const createdAt = doc?.createdAt ?? memory?.createdAt const url = doc?.url ?? memory?.url return ( <> {/* Backdrop */}
{/* Popover */}
e.stopPropagation()} className="fixed z-[1000] bg-white/5 backdrop-blur-xl border border-white/25 rounded-xl p-4 w-80 shadow-2xl" style={{ left: `${x}px`, top: `${y}px`, }} >
{/* Header */}
{isMemory ? ( ) : ( )}

{isMemory ? "Memory" : "Document"}

{/* Content */}
{/* Title */}
Title

{title || "Untitled"}

{/* Summary/Content */} {summary && (
{isMemory ? "Content" : "Summary"}

{summary}

)} {/* Type */}
Type

{type}

{/* Memory Count - only for documents */} {doc && (
Memory Count

{doc.memoryEntries?.length || 0} memories

)} {/* URL */} {(documentUrl || url) && ( )} {/* Footer */}
{createdAt && (
{new Date(createdAt).toLocaleDateString()}
)}
{node.id}
) })