'use client'; import { useEffect, useState } from 'react'; import { X, MessageSquare, ExternalLink } from 'lucide-react'; import { useGraphStore, GraphNode } from '@/store/graph'; import { entityColor } from '@/lib/constants'; import { Badge } from '@/components/ui/badge'; interface EntityDetail { description?: string; sourceDoc?: string; relationships: { target: string; type: string; confidence?: number }[]; } export function EntityPanel({ onAsk, }: { onAsk?: (name: string) => void; }) { const selected = useGraphStore((s) => s.selectedEntity); const close = () => useGraphStore.getState().selectEntity(null); const [detail, setDetail] = useState(null); useEffect(() => { if (!selected) { setDetail(null); return; } // Build relationships by scanning graph links const { data } = useGraphStore.getState(); const rels = data.links .filter((l) => l.source === selected.id || l.target === selected.id) .map((l) => ({ target: l.source === selected.id ? l.target : l.source, type: l.type, confidence: l.confidence, })); setDetail({ description: selected.description, sourceDoc: selected.sourceDoc, relationships: rels, }); }, [selected]); if (!selected) return null; return (
{selected.name}
{selected.type}
{detail?.description && (

{detail.description}

)} {detail?.sourceDoc && (
Source: {detail.sourceDoc}
)}

Relationships ({detail?.relationships.length || 0})

    {detail?.relationships.map((r, i) => (
  • {r.type.replace(/_/g, ' ').toLowerCase()} {r.target}
  • ))}
{onAsk && (
)}
); }