import React, { useState } from 'react'; import { Card } from './ui/card'; import { Button } from './ui/button'; import { useBasicEcosystemMetrics, useHarmonicMetrics } from '@/hooks/useEcosystemData'; interface PhaseData { guardianPhase: number; anchorPhase: number; phaseDiff: number; coherence: number; synchrony: number; } export const AnalysisModePanel: React.FC<{ tool: string }> = ({ tool }) => { const [phaseData, setPhaseData] = useState([]); const [isAnalyzing, setIsAnalyzing] = useState(false); const [memoryTrace, setMemoryTrace] = useState([]); // Use real ecosystem data const basicMetrics = useBasicEcosystemMetrics(); const harmonicMetrics = useHarmonicMetrics(); const liveCoherence = basicMetrics.coherence; const lambda = basicMetrics.frequency / 528; const resonance = harmonicMetrics.harmonicFidelity; const phaseAlignment = harmonicMetrics.probabilityFusion; const dimensionalCoherence = harmonicMetrics.coherence; const generatePhaseData = (): PhaseData[] => { return Array.from({ length: 50 }, (_, i) => { const t = i / 50; // Use live coherence to influence phase calculations const guardianPhase = Math.sin(t * 4 * Math.PI + lambda) * 180; const anchorPhase = Math.cos(t * 3 * Math.PI + phaseAlignment) * 180; const phaseDiff = Math.abs(guardianPhase - anchorPhase); // Blend live coherence with computed coherence const computedCoherence = Math.exp(-phaseDiff / 180) * 0.8; const finalCoherence = computedCoherence * 0.7 + liveCoherence * 0.3; const synchrony = finalCoherence > 0.6 ? 1 : 0; return { guardianPhase, anchorPhase, phaseDiff, coherence: finalCoherence, synchrony }; }); }; const runAnalysis = async () => { setIsAnalyzing(true); await new Promise(resolve => setTimeout(resolve, 1200)); const data = generatePhaseData(); setPhaseData(data); // Generate memory trace based on real resonance const trace = Array.from({ length: 20 }, (_, i) => { const base = resonance * 0.6; const variation = dimensionalCoherence * 0.4; return Math.min(1, Math.max(0, base + variation * Math.sin(i * 0.5))); }); setMemoryTrace(trace); setIsAnalyzing(false); }; const renderPhaseDynamics = () => (

Phase Dynamics Interpreter

{/* Live metrics display */}
Live Γ: {liveCoherence.toFixed(3)}
Live Λ: {lambda.toFixed(3)}
{phaseData.length > 0 && (
{phaseData[phaseData.length - 1]?.guardianPhase.toFixed(1)}°
Guardian Phase
{phaseData[phaseData.length - 1]?.anchorPhase.toFixed(1)}°
Anchor Phase
{phaseData[phaseData.length - 1]?.coherence.toFixed(3)}
Coherence
Guardian (Primary) • Anchor (Green)
Synchrony Events: {phaseData.filter(d => d.synchrony === 1).length}/50 • Avg Coherence: {(phaseData.reduce((sum, d) => sum + d.coherence, 0) / phaseData.length).toFixed(3)}
)}
); const renderMemoryTracer = () => (

Symbolic Memory Tracer

{/* Live metrics */}
Live Resonance: {resonance.toFixed(3)} | Dimensional Coherence: {dimensionalCoherence.toFixed(3)}
{memoryTrace.length > 0 && (
Pattern Correlation Over Time
{memoryTrace.map((value, idx) => (
))}
Peak Correlation
{Math.max(...memoryTrace).toFixed(3)}
Memory Persistence
{(memoryTrace.filter(v => v > 0.5).length / memoryTrace.length * 100).toFixed(0)}%
)}
); const renderStabilityAnalyst = () => (

Stability Analyst

0.5 ? 'bg-success/10 border-success/30' : 'bg-muted/30 border-border'}`}>
0.5 ? 'bg-success' : 'bg-muted-foreground'}`} /> 0.5 ? 'text-success' : 'text-muted-foreground'}`}>Bounded Regime
0.5 ? 'text-success/80' : 'text-muted-foreground'}`}> {liveCoherence > 0.5 ? 'System exhibits stable oscillations within expected parameters' : 'Waiting for stable coherence levels'}
0.7 ? 'bg-primary/10 border-primary/30' : 'bg-warning/10 border-warning/30'}`}>
0.7 ? 'bg-primary' : 'bg-warning'}`} /> 0.7 ? 'text-primary' : 'text-warning'}`}> {liveCoherence > 0.7 ? 'Optimal Zone' : 'Edge Dynamics'}
0.7 ? 'text-primary/80' : 'text-warning/80'}`}> {liveCoherence > 0.7 ? 'Operating in optimal coherence zone' : 'Approaching phase transition threshold'}
); switch (tool) { case 'phase': return {renderPhaseDynamics()}; case 'memory': return {renderMemoryTracer()}; case 'stability': return {renderStabilityAnalyst()}; case 'temporal': return
Temporal Synthesizer Interface
; default: return
Select an analysis tool
; } };