"use client"; import { useRef, useState } from "react"; import { AnimatePresence, motion } from "framer-motion"; import { CheckCircle2, HelpCircle, XCircle } 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"; type Answer = "Ja" | "Nein"; export default function JaNeinGenerator() { const [question, setQuestion] = useState(""); const [answer, setAnswer] = useState(null); const [asking, setAsking] = useState(false); const [history, setHistory] = useState([]); const cardRef = useRef(null); const { play } = useSound(); const reduced = usePrefersReducedMotion(); const ask = () => { if (asking) return; const pick: Answer = Math.random() < 0.5 ? "Ja" : "Nein"; setAsking(true); setAnswer(null); play("whoosh"); const reveal = () => { setAsking(false); setAnswer(pick); setHistory((h) => [pick, ...h].slice(0, 10)); play(pick === "Ja" ? "win" : "pop"); if (pick === "Ja") popConfetti(); }; if (reduced) { gsap.delayedCall(0.25, reveal); return; } const tl = gsap.timeline({ onComplete: reveal }); tl.to(cardRef.current, { rotate: -6, x: -10, duration: 0.09, ease: "power1.inOut", }) .to(cardRef.current, { rotate: 6, x: 10, duration: 0.09, ease: "power1.inOut", }) .repeat(3) .to(cardRef.current, { rotate: 0, x: 0, duration: 0.2, ease: "power2.out", }); }; return (
{/* Bühne */}
setQuestion(e.target.value)} maxLength={100} placeholder="Deine Ja/Nein-Frage (optional) …" aria-label="Deine Frage an den Ja-Nein-Generator" className="w-full max-w-sm 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" />
{asking ? "Überlegt …" : "Ja oder Nein?"}

{question.trim() ? `„${question.trim()}“` : "Stell eine Frage – oder lass dich einfach überraschen."}

{/* Info & Verlauf */}

So funktioniert's

Frage eingeben (optional), auf die Karte oder den Button tippen – der Generator entscheidet zufällig zwischen Ja und Nein. Perfekt für schnelle Entscheidungen ohne langes Abwägen.

{history.length > 0 && (

Verlauf

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