// Guided tour overlay. Reads the active scenario's tour script and // anchors a step-card to the named region. import { useEffect } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { useApp, scenarioById } from "../state/store"; import { Sparkles, ChevL, ChevR, Close } from "./icons"; export default function Tour() { const tour = useApp((s) => s.tour); const scenarioId = useApp((s) => s.scenarioId); const endTour = useApp((s) => s.endTour); const tourPrev = useApp((s) => s.tourPrev); const tourNext = useApp((s) => s.tourNext); const sc = scenarioById(scenarioId); const step = sc?.tour[tour.index] ?? null; useEffect(() => { if (!tour.active) return; const onKey = (e: KeyboardEvent) => { if (e.key === "ArrowRight" || e.key === "Enter") { e.preventDefault(); tourNext(); } if (e.key === "ArrowLeft") { e.preventDefault(); tourPrev(); } if (e.key === "Escape") { e.preventDefault(); endTour(); } }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [tour.active, tourPrev, tourNext, endTour]); if (!tour.active || !step || !sc) return null; const last = tour.index === sc.tour.length - 1; const first = tour.index === 0; return (
Guided tour ยท {tour.index + 1} / {sc.tour.length}

{step.title}

{step.body}

{last ? ( ) : ( )}
); }