"use client"; import { useEffect, useCallback, useRef } from "react"; interface StepControlsProps { currentStep: number; totalSteps: number; isPlaying: boolean; onStepForward: () => void; onStepBack: () => void; onTogglePlay: () => void; onReset: () => void; canStepForward: boolean; canStepBack: boolean; playIntervalMs?: number; } export function StepControls({ currentStep, totalSteps, isPlaying, onStepForward, onStepBack, onTogglePlay, onReset, canStepForward, canStepBack, playIntervalMs = 950, }: StepControlsProps) { const timerRef = useRef | null>(null); // Auto-play timer useEffect(() => { if (isPlaying && canStepForward) { timerRef.current = setInterval(() => { onStepForward(); }, playIntervalMs); } return () => { if (timerRef.current) clearInterval(timerRef.current); }; }, [isPlaying, canStepForward, onStepForward, playIntervalMs]); // Keyboard shortcuts const handleKeyDown = useCallback( (e: KeyboardEvent) => { const el = e.target as HTMLElement; const tag = el.tagName; if (["INPUT", "TEXTAREA", "SELECT"].includes(tag)) return; if (el.closest("button, [role='button'], a")) return; if (e.key === "ArrowRight" || e.key === " ") { e.preventDefault(); if (canStepForward) onStepForward(); } if (e.key === "ArrowLeft") { e.preventDefault(); if (canStepBack) onStepBack(); } if (e.key.toLowerCase() === "p") onTogglePlay(); if (e.key.toLowerCase() === "r") onReset(); }, [canStepForward, canStepBack, onStepForward, onStepBack, onTogglePlay, onReset], ); useEffect(() => { document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); }, [handleKeyDown]); const progress = totalSteps > 0 ? (currentStep / totalSteps) * 100 : 0; return (
{/* Progress bar */} {totalSteps > 0 && (
Step {currentStep} of {totalSteps} {Math.round(progress)}%
)} {/* Controls */}
{/* Keyboard hint */}

Space{" / "} {" "} next{" · "} {" "} back{" · "} P{" "} play{" · "} R{" "} reset

); }