import { useCallback, useRef, useState } from "react"; import { useVideoPlayerState } from "../VideoContext"; interface BackdropControlProps { children?: React.ReactNode; } export function BackdropControl(props: BackdropControlProps) { const { videoState } = useVideoPlayerState(); const [moved, setMoved] = useState(false); const timeout = useRef | null>(null); const handleMouseMove = useCallback(() => { setMoved(true); if (timeout.current) clearTimeout(timeout.current); timeout.current = setTimeout(() => { setMoved(false); timeout.current = null; }, 3000); }, [timeout, setMoved]); const handleClick = useCallback(() => { if (videoState.isPlaying) videoState.pause(); else videoState.play(); }, [videoState]); const showUI = moved || videoState.isPaused; return (
{showUI ? props.children : null}
); }