"use client"; import { useRef, useState } from "react"; import { AnimatePresence, motion } from "framer-motion"; import { Hash } from "lucide-react"; import { gsap } from "@/lib/gsap"; import { popConfetti } from "@/lib/confetti"; import { useSound } from "@/components/providers/sound-provider"; import { useLocalStorage } from "@/hooks/use-local-storage"; import { usePrefersReducedMotion } from "@/hooks/use-prefers-reduced-motion"; const randInt = (lo: number, hi: number) => lo + Math.floor(Math.random() * (hi - lo + 1)); const toInt = (raw: string) => { const n = Math.round(Number(raw)); return Number.isFinite(n) ? n : 0; }; export default function RandomNumber() { const [min, setMin] = useLocalStorage("num-min", 1); const [max, setMax] = useLocalStorage("num-max", 100); const [display, setDisplay] = useState(null); const [rolling, setRolling] = useState(false); const [done, setDone] = useState(false); const lastPaintRef = useRef(0); const { play } = useSound(); const reduced = usePrefersReducedMotion(); const roll = () => { if (rolling) return; const lo = Math.min(min, max); const hi = Math.max(min, max); const result = randInt(lo, hi); setRolling(true); setDone(false); play("whoosh"); const dur = reduced ? 0.3 : 1.7; const proxy = { p: 0 }; lastPaintRef.current = 0; gsap.to(proxy, { p: 1, duration: dur, ease: "power2.out", onUpdate: () => { const now = performance.now(); // Wechsel-Intervall wächst → Slot-Machine-Effekt const interval = reduced ? 60 : 28 + 240 * proxy.p; if (now - lastPaintRef.current > interval) { lastPaintRef.current = now; setDisplay(String(randInt(lo, hi))); } }, onComplete: () => { setDisplay(String(result)); setRolling(false); setDone(true); play("pop"); popConfetti(); }, }); }; return (
{/* Anzeige */}
{display === null ? ( Bereit, wenn du es bist. ) : ( {display} )}
{rolling ? "Rollt …" : "Zahl generieren"}

Zufallszahl zwischen {Math.min(min, max)} und {Math.max(min, max)}

{/* Einstellungen */}

Zahlenraum

Perfekt für Lose, Teams oder „Wie viele Liegestütze?“. Reihenfolge von Min & Max ist egal.

); }