import { useEffect, useRef } from 'react'; import { motion } from 'framer-motion'; import { Play, Pause, FastForward, RotateCcw } from 'lucide-react'; import { cn } from '@/lib/utils'; interface AutoPlayControlsProps { isPlaying: boolean; speed: number; round: number; maxRounds: number; done: boolean; onTogglePlay: () => void; onSpeedChange: (speed: number) => void; className?: string; } const SPEEDS = [ { value: 0.5, label: '0.5x' }, { value: 1, label: '1x' }, { value: 2, label: '2x' }, { value: 4, label: '4x' }, ]; export default function AutoPlayControls({ isPlaying, speed, round, maxRounds, done, onTogglePlay, onSpeedChange, className, }: AutoPlayControlsProps) { return (
Auto-Play
{SPEEDS.map((s) => ( ))}
0 ? (round / maxRounds) * 100 : 0}%` }} transition={{ duration: 0.3 }} />
Round {round} {maxRounds} max
{isPlaying && ( Running at {speed}x speed... )}
); } export function useAutoPlay( onStep: (() => void) | undefined, speed: number, isPlaying: boolean, done: boolean, loading: boolean, ) { const timerRef = useRef | null>(null); useEffect(() => { if (!isPlaying || done || loading || !onStep) { if (timerRef.current) clearTimeout(timerRef.current); return; } const delay = 3000 / speed; timerRef.current = setTimeout(() => { onStep(); }, delay); return () => { if (timerRef.current) clearTimeout(timerRef.current); }; }, [isPlaying, done, loading, speed, onStep]); }