import React, { useState, useEffect } from 'react'; import { Play, RotateCcw, Info, Sparkles, Sun, Bot, BookOpen, Rocket } from 'lucide-react'; const CometSpectroscopy = () => { const [molecule, setMolecule] = useState('C2'); const [animationState, setAnimationState] = useState('idle'); // idle, absorbing, emitting const [activeTransition, setActiveTransition] = useState(null); const [cometColor, setCometColor] = useState('rgba(255, 255, 255, 0.1)'); const [glowIntensity, setGlowIntensity] = useState(0); // AI State const [aiResponse, setAiResponse] = useState(''); const [isAiLoading, setIsAiLoading] = useState(false); const [aiMode, setAiMode] = useState(null); // 'science' or 'creative' // Molecule Data Configuration const molecules = { C2: { name: "Diatomic Carbon (C₂)", description: "Ansvarlig for den ikoniske grønne farve i kometens hoved (koma).", levels: [ { id: 'd', label: 'd ³Πg (Excited)', energy: 85, color: '#4ade80' }, { id: 'a', label: 'a ³Πu (Metastable)', energy: 15, color: '#facc15' }, { id: 'X', label: 'X ¹Σg⁺ (Ground)', energy: 5, color: '#94a3b8' } ], transitions: [ { id: 'swan', name: 'Swan Bands (Green)', from: 'd', to: 'a', wavelength: 516, color: '#00ff00', photonColor: 'text-green-400', desc: "Elektronen falder ikke til bunden, men til 'a'-niveauet." } ] }, CN: { name: "Cyanogen (CN)", description: "Dominerer ofte kometens spektrum med violet lys nær solen.", levels: [ { id: 'B', label: 'B ²Σ⁺ (Violet State)', energy: 90, color: '#a78bfa' }, { id: 'A', label: 'A ²Π (Red State)', energy: 45, color: '#f87171' }, { id: 'X', label: 'X ²Σ⁺ (Ground)', energy: 5, color: '#94a3b8' } ], transitions: [ { id: 'violet', name: 'Violet System', from: 'B', to: 'X', wavelength: 388, color: '#8b5cf6', photonColor: 'text-violet-400', desc: "Meget kraftig emission i nær-UV/violet." }, { id: 'red', name: 'Red System', from: 'A', to: 'X', wavelength: 790, // Representative IR/Red color: '#ef4444', photonColor: 'text-red-500', desc: "Svagere rødlig glød, ofte svær at se." } ] } }; const currentData = molecules[molecule]; // Gemini API Integration const callGemini = async (mode) => { setIsAiLoading(true); setAiMode(mode); setAiResponse(''); const apiKey = ""; // API Key handled by environment let prompt = ""; if (mode === 'science') { prompt = `Forklar på dansk, kort og præcist, betydningen af molekylet ${currentData.name} i kometer. Nævn en kendt komet (som f.eks. den grønne komet C/2022 E3 for C2) og forklar hvorfor vi ser disse emissionslinjer. Hold det under 100 ord.`; } else { prompt = `Skriv en meget kort (under 80 ord) sci-fi logbogspost på dansk fra en rumskibskaptajn, der flyver gennem en komet-hale rig på ${currentData.name}. Beskriv den visuelle oplevelse af farven (${molecule === 'C2' ? 'glødende smaragdgrøn' : 'mystisk ultraviolet/violet'}).`; } try { const response = await fetch( `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-09-2025:generateContent?key=${apiKey}`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ contents: [{ parts: [{ text: prompt }] }], }), } ); const data = await response.json(); const text = data.candidates?.[0]?.content?.parts?.[0]?.text || "Kunne ikke hente data fra Gemini."; setAiResponse(text); } catch (error) { setAiResponse("Der opstod en fejl ved forbindelse til AI."); console.error(error); } finally { setIsAiLoading(false); } }; const handleTransition = (transition) => { if (animationState !== 'idle') return; setActiveTransition(transition); setAnimationState('absorbing'); setCometColor('rgba(255, 255, 255, 0.1)'); // Reset color setGlowIntensity(0); // Sequence: Absorb (Up) -> Pause -> Emit (Down + Photon) setTimeout(() => { setAnimationState('emitting'); // Flash the comet color when emission starts setTimeout(() => { setCometColor(transition.color); setGlowIntensity(1); setTimeout(() => setGlowIntensity(0.5), 500); }, 300); setTimeout(() => { setAnimationState('idle'); // setActiveTransition(null); // Keep selection for viewing info }, 2000); }, 1000); }; // Helper to get Y position (%) based on energy level const getY = (levelId) => { const level = currentData.levels.find(l => l.id === levelId); return level ? 100 - level.energy : 0; }; return (
{/* Header */}

Comet Spectroscopy Explorer

Interaktivt energidiagram for {molecule === 'C2' ? 'Diatomisk Kulstof' : 'Cyanogen'}

{['C2', 'CN'].map((m) => ( ))}
{/* Main Content Grid */}
{/* LEFT COLUMN: Energy Diagram */}

Jablonski Energidiagram

Energy (eV) ↑
{/* Y-Axis Arrow */}
{/* Energy Levels */} {currentData.levels.map((level) => (
{level.label}
))} {/* Electron Animation */} {activeTransition && (
l.id === activeTransition.from).energy}%` : `${currentData.levels.find(l => l.id === activeTransition.to).energy}%`, opacity: animationState === 'idle' ? 0 : 1 }} >
)} {/* Photon Animation (Wavy line) */} {animationState === 'emitting' && activeTransition && (
l.id === activeTransition.to).energy + currentData.levels.find(l => l.id === activeTransition.from).energy) / 2}%` }} > hν (~{activeTransition.wavelength}nm)
)} {/* Sunlight Pump Animation */} {animationState === 'absorbing' && (
)}
{/* Controls */}
{currentData.transitions.map((t) => ( ))}
{activeTransition && (
{activeTransition.desc}
)}
{/* RIGHT COLUMN: Comet Visualizer & AI */}
{/* Comet View */}
{/* Stars Background */}
{/* The Comet */}
{/* Nucleus */}
{/* Coma (Head) - The glowing part */}
{/* Tail (Simple Dust) */}
Telescopic Simulation View
Filter: Visible Light
{/* AI Features Section - NEW */}

Gemini AI Assistent

{/* AI Output Box */}
{isAiLoading ? (
Gemini tænker...
) : aiResponse ? (

{aiResponse}

Genereret af Gemini AI
) : (
Tryk på en knap for at få AI til at analysere molekylet...
)}
{/* Spectrum Bar */}

Emissionsspektrum

{/* Dimmer */} {/* Wavelength Markers */}
400nm
550nm
750nm
{/* Active Line Marker */} {activeTransition && animationState !== 'idle' && (
{activeTransition.wavelength}nm
)}
); }; export default CometSpectroscopy;