"use client"; import { useRef, useState } from "react"; import { AnimatePresence, motion } from "framer-motion"; import { Scale, Sparkles } from "lucide-react"; import { gsap } from "@/lib/gsap"; import { popConfetti } from "@/lib/confetti"; import { useSound } from "@/components/providers/sound-provider"; import { usePrefersReducedMotion } from "@/hooks/use-prefers-reduced-motion"; const MAX_LEN = 28; export default function EntwederOder() { const [optionA, setOptionA] = useState(""); const [optionB, setOptionB] = useState(""); const [result, setResult] = useState<"A" | "B" | null>(null); const [deciding, setDeciding] = useState(false); const [history, setHistory] = useState([]); const cardRef = useRef(null); const { play } = useSound(); const reduced = usePrefersReducedMotion(); const labelA = optionA.trim() || "Option A"; const labelB = optionB.trim() || "Option B"; const decide = () => { if (deciding) return; const pick: "A" | "B" = Math.random() < 0.5 ? "A" : "B"; setDeciding(true); setResult(null); play("whoosh"); const reveal = () => { setDeciding(false); setResult(pick); setHistory((h) => [pick === "A" ? labelA : labelB, ...h].slice(0, 10)); play("win"); popConfetti(); }; if (reduced) { gsap.delayedCall(0.25, reveal); return; } const tl = gsap.timeline({ onComplete: reveal }); tl.to(cardRef.current, { rotate: -5, duration: 0.1, ease: "power1.inOut", }) .to(cardRef.current, { rotate: 5, duration: 0.1, ease: "power1.inOut", }) .repeat(3) .to(cardRef.current, { rotate: 0, duration: 0.2, ease: "power2.out" }); }; return (
{/* Bühne */}
setOptionA(e.target.value)} maxLength={MAX_LEN} placeholder="Option A" aria-label="Erste Option" className="w-full rounded-full border border-line bg-surface px-5 py-3 text-center text-sm font-medium shadow-soft outline-none transition focus:border-primary/60 focus:ring-2 focus:ring-primary/20" /> oder setOptionB(e.target.value)} maxLength={MAX_LEN} placeholder="Option B" aria-label="Zweite Option" className="w-full rounded-full border border-line bg-surface px-5 py-3 text-center text-sm font-medium shadow-soft outline-none transition focus:border-primary/60 focus:ring-2 focus:ring-primary/20" />
{deciding ? "Wägt ab …" : "Entweder oder?"}

{optionA.trim() || optionB.trim() ? `„${labelA}“ oder „${labelB}“` : "Trage zwei Optionen ein – oder entscheide direkt."}

{/* Info & Verlauf */}

So funktioniert's

Beide Optionen eintragen, auf die Karte oder den Button tippen – der Generator wählt zufällig eine davon aus. Beide haben dieselbe Chance. Achte auf deine erste Reaktion: Erleichterung oder der Wunsch nach einem zweiten Versuch verrät oft mehr als das Ergebnis selbst.

{history.length > 0 && (

Verlauf

{history.map((entry, i) => ( {entry} ))}
)}
); }