"use client"; import { useRef, useState } from "react"; import { AnimatePresence, motion } from "framer-motion"; import { ListChecks, Sparkles } from "lucide-react"; import { gsap } from "@/lib/gsap"; import { celebrateConfetti } 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 DEFAULT_LIST = "Anna\nBen\nClara\nDavid"; export default function ListPicker() { const [text, setText] = useLocalStorage("list-items", DEFAULT_LIST); const [removeAfterDraw, setRemoveAfterDraw] = useLocalStorage( "list-remove", false, ); const [display, setDisplay] = useState(null); const [drawing, setDrawing] = useState(false); const [winner, setWinner] = useState(null); const [error, setError] = useState(false); const lastPaintRef = useRef(0); const textareaRef = useRef(null); const { play } = useSound(); const reduced = usePrefersReducedMotion(); const items = text .split("\n") .map((s) => s.trim()) .filter(Boolean); const draw = () => { if (drawing) return; if (items.length < 2) { setError(true); play("tick"); gsap.fromTo( textareaRef.current, { x: -7 }, { x: 0, duration: 0.4, ease: "elastic.out(2.5, 0.35)" }, ); return; } setError(false); const pick = items[Math.floor(Math.random() * items.length)]; setDrawing(true); setWinner(null); play("whoosh"); const dur = reduced ? 0.35 : 2.0; const proxy = { p: 0 }; lastPaintRef.current = 0; gsap.to(proxy, { p: 1, duration: dur, ease: "power2.out", onUpdate: () => { const now = performance.now(); const interval = reduced ? 60 : 30 + 260 * proxy.p; if (now - lastPaintRef.current > interval) { lastPaintRef.current = now; setDisplay(items[Math.floor(Math.random() * items.length)]); } }, onComplete: () => { setDisplay(pick); setWinner(pick); setDrawing(false); play("win"); celebrateConfetti(); if (removeAfterDraw) { setText( items .filter((item) => item !== pick) .join("\n"), ); } }, }); }; return (
{/* Liste */}

Deine Liste ({items.length})