import React, { useState, useEffect } from 'react'; import { X, Network, ArrowRight, ArrowLeft, ArrowLeftRight, Code2, ShieldAlert, GitCommit, Layers, Workflow, FileText, Check, Copy, ExternalLink, Sparkles, BookOpen, Zap, Lightbulb } from 'lucide-react'; import { CATEGORY_COLORS, CATEGORY_LABELS } from './types'; import type { GraphNode, ArchitectureNodeDetails } from './types'; import { MiniDependencyPreviewTree } from './MiniDependencyPreviewTree'; import { apiUrl } from '../../../lib/api'; interface NodeDetailsPanelProps { node: GraphNode; repoName: string; onClose: () => void; onExpand: (nodeId: string) => void; onTraceForward: (nodeId: string) => void; onTraceBackward: (nodeId: string) => void; onTraceBoth: (nodeId: string) => void; onOpenDiagramModal: (nodeId: string) => void; onSelectNode: (nodeId: string) => void; className?: string; } export const NodeDetailsPanel: React.FC = ({ node, repoName, onClose, onExpand, onTraceForward, onTraceBackward, onTraceBoth, onOpenDiagramModal, onSelectNode, className, }) => { const [tab, setTab] = useState<'overview' | 'architecture' | 'metrics' | 'deps' | 'git' | 'guidance' | 'impact' | 'recommendations'>('overview'); const [details, setDetails] = useState(null); const [loading, setLoading] = useState(false); const [copied, setCopied] = useState(false); useEffect(() => { const fetchNodeDetails = async () => { setLoading(true); const [owner, name] = repoName.split('/'); try { const res = await fetch(apiUrl(`/api/v1/architecture/${owner}/${name}/node-details/${encodeURIComponent(node.id)}`)); if (res.ok) { const data = await res.json(); setDetails(data); } } catch { /* fallback to defaults */ } finally { setLoading(false); } }; fetchNodeDetails(); }, [repoName, node.id]); const handleCopyPath = () => { navigator.clipboard.writeText(node.id); setCopied(true); setTimeout(() => setCopied(false), 2000); }; const handleVSCodeOpen = () => { window.open(`vscode://file/${node.id}`); }; const color = CATEGORY_COLORS[node.category] ?? CATEGORY_COLORS.regular; const categoryLabel = CATEGORY_LABELS[node.category] ?? node.category; const fileName = node.id.split('/').pop() ?? node.id; const dirPath = node.id.includes('/') ? node.id.substring(0, node.id.lastIndexOf('/')) : ''; const positionClass = className ?? 'fixed inset-x-0 bottom-0 max-h-[80vh] md:absolute md:right-0 md:top-0 md:bottom-0 md:max-h-none md:w-[410px]'; /** Renders a backend-provided value, or an unavailable marker when it is absent. */ const renderValue = (value: string | number | null | undefined, suffix = ''): string => value === null || value === undefined || value === '' ? '—' : `${value}${suffix}`; /* One absent-data marker for the whole workspace: mono, uppercase and quiet, matching the diagnostics panels and the impact readout. Italic sans read as prose here and made a missing field look like a comment. */ const UNAVAILABLE = ( NOT AVAILABLE ); /* An evidence surface, not a dashboard drawer: the panel resolves out of a blur, a vertical hairline attaches it to the finding it is explaining, and the body arrives in order — identity, then metadata, then relationships, then actions. The root element is keyed on the node so re-targeting replays the resolve. This is ARIA explaining something it has just identified, and it should read that way every time, not only the first time the panel opens. */ return (
{/* Header */}
{/* Network, not a sparkle: this inspector reports topology, and the internal "v2" tag was never meant to reach the interface. */}

{fileName}

{dirPath && ( {dirPath}/ )}
{/* 8 Inspector Subtabs */}
{[ { id: 'overview', label: 'Overview' }, { id: 'architecture', label: 'Patterns' }, { id: 'metrics', label: 'Metrics' }, { id: 'deps', label: 'Tree' }, { id: 'git', label: 'Git' }, { id: 'guidance', label: 'Guidance' }, { id: 'impact', label: 'Impact' }, { id: 'recommendations', label: 'Suggest' }, ].map((t) => ( ))}
{/* Content Body */}
{tab === 'overview' && ( /* `evidence-stack` sequences its direct children: what the module is, then how it is classified, then what you can do with it, then how to traverse from it. Positional stagger, so no child knows its own index. */
{/* Business Responsibility */}
Business Responsibility

{details?.business_responsibility || UNAVAILABLE}

{/* Category & Layer Badges */}
{categoryLabel} {details?.layer && ( {details.layer} Layer )}
{/* Quick Actions */}
Smart Actions
{/* Cross-Surface Intelligence Actions */}
{/* Graph Traversal */}
Graph Traversal
)} {tab === 'architecture' && (
Architectural Layer
{details?.layer ? `${details.layer} Layer` : UNAVAILABLE}
Detected Design Patterns
{details?.patterns?.length ? details.patterns.map((p) => ( {p} )) : UNAVAILABLE}
{/* System Position Metrics */}
System Position Metrics
Entry Distance {renderValue(details?.system_position?.distance_from_entry_point, ' hops')}
Infra Distance {renderValue(details?.system_position?.distance_from_infrastructure, ' hops')}
{/* Suggested Reading Sequence */}
Suggested Reading Sequence
{details?.suggested_reading_order?.length ? details.suggested_reading_order.map((step, idx) => (
{step}
)) : UNAVAILABLE}
)} {tab === 'metrics' && (
Advanced Metrics Suite
Instability (I) {renderValue(details?.metrics?.instability)}
Main Seq Dist (D) {renderValue(details?.metrics?.distance_main_sequence)}
Maintainability (MI) {renderValue(details?.metrics?.maintainability_index, '/100')}
Complexity v(G) {renderValue(details?.metrics?.cyclomatic_complexity)}
Afferent (Ca) {renderValue(details?.metrics?.afferent_coupling)}
Efferent (Ce) {renderValue(details?.metrics?.efferent_coupling)}
Lines of Code {renderValue(details?.metrics?.lines_of_code)}
Comment Density {renderValue(details?.metrics?.comment_density, '%')}
)} {tab === 'deps' && ( )} {tab === 'git' && (
Git History & Churn
First Created: {renderValue(details?.git_metrics?.created)}
Last Modified: {renderValue(details?.git_metrics?.last_modified)}
Commit Count: {renderValue(details?.git_metrics?.commit_count, ' commits')}
Contributors: {renderValue(details?.git_metrics?.contributors_count, ' authors')}
{details?.git_metrics?.latest_commit_message && (
Latest Commit

"{details.git_metrics.latest_commit_message}"

)}
)} {tab === 'guidance' && (
Developer Modifications
{details?.developer_guidance?.common_modification_reasons?.length ? (
    {details.developer_guidance.common_modification_reasons.map((r, i) => (
  • {r}
  • ))}
) : ( UNAVAILABLE )}
Risk Indicators
{details?.risk_indicators?.length ? details.risk_indicators.map((rk, idx) => (
{rk.label}: {rk.description}
)) : UNAVAILABLE}
)} {tab === 'impact' && (
Blast Radius Assessment
Risk Level: {renderValue(details?.impact?.risk_level)} Affected Files: {renderValue(details?.impact?.total_affected_files)}
Affected Entry Points & APIs
{details?.impact?.affected_apis?.length ? details.impact.affected_apis.map((api, i) => (
{api}
)) : UNAVAILABLE}
)} {tab === 'recommendations' && (
Architecture Suggestions {details?.recommendations?.length ? details.recommendations.map((rec, i) => (
{rec.title} {rec.priority}

{rec.reason}

💡 {rec.suggestion}
)) : UNAVAILABLE}
)}
); };