/* Shared components — PromptOptimizerModal, TrendChart, ReportChat Requires api.js to be loaded first. */ const { useState: useStateC, useEffect: useEffectC, useRef: useRefC } = React; /* ============================================================ PROMPT OPTIMIZER MODAL Props: rawPrompt — string already built from form fields onClose — () => void onLaunched — (simId: string) => void called after simulation started ============================================================ */ function PromptOptimizerModal({ rawPrompt, onClose, onLaunched }) { const [phase, setPhase] = useStateC('optimizing'); // optimizing | review | launching | error const [result, setResult] = useStateC(null); const [edited, setEdited] = useStateC(''); const [err, setErr] = useStateC(''); useEffectC(() => { let live = true; window.RICS_API.optimizePrompt(rawPrompt) .then((r) => { if (!live) return; setResult(r); setEdited(r.improved); setPhase('review'); }) .catch((e) => { if (!live) return; setErr(e.message); setPhase('error'); }); return () => { live = false; }; }, [rawPrompt]); const handleConfirm = async () => { setPhase('launching'); try { // 3-Schritt-Lifecycle: create → prepare → start const created = await window.RICS_API.createSimulation({ prompt: edited }); const simId = created.simulation_id || created.simulationId || created.id; await window.RICS_API.prepareSimulation({ simulation_id: simId }); await window.RICS_API.startSimulation({ simulation_id: simId }); onLaunched(simId); } catch (e) { setErr(e.message); setPhase('error'); } }; return (
{ if (e.target === e.currentTarget && phase !== 'launching') onClose(); }} >
{/* Header */}
Prompt-Optimierung · KI-gestützt

{phase === 'optimizing' ? 'Prompt wird strukturiert…' : phase === 'launching' ? 'Simulation wird gestartet…' : phase === 'error' ? 'Fehler aufgetreten' : 'Prompt prüfen und bestätigen'}

{phase !== 'launching' && ( )}
{/* Body */}
{/* Loading state */} {(phase === 'optimizing' || phase === 'launching') && (
{phase === 'optimizing' ? 'GeoStrat-Prompt-Engine · aktiv' : 'Backend-Simulation wird initialisiert…'}
)} {/* Error state */} {phase === 'error' && (
Fehler

{err}

)} {/* Review state */} {phase === 'review' && result && (
{/* Side-by-side comparison */}
Original
{result.original}
Verbessert · editierbar