import { useState, useRef, useEffect } from 'react'; import { X, Download, Film, Play, Pause, SkipBack, SkipForward, Pencil } from 'lucide-react'; import { Button } from './Button'; import { TimelapseEditorModal } from './TimelapseEditorModal'; import { formatMediaTime } from '../utils/date'; interface TimelapseViewerProps { src: string; title: string; downloadFilename: string; archiveId?: number; onClose: () => void; onEdit?: () => void; } const SPEED_OPTIONS = [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4]; export function TimelapseViewer({ src, title, downloadFilename, archiveId, onClose, onEdit, }: TimelapseViewerProps) { const videoRef = useRef(null); const [isPlaying, setIsPlaying] = useState(true); const [playbackRate, setPlaybackRate] = useState(1); // Default to 1x const [currentTime, setCurrentTime] = useState(0); const [duration, setDuration] = useState(0); const [showEditor, setShowEditor] = useState(false); useEffect(() => { const video = videoRef.current; if (video) { video.playbackRate = playbackRate; } }, [playbackRate]); // Close on Escape key useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') { onClose(); } }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, [onClose]); useEffect(() => { const video = videoRef.current; if (!video) return; const handleTimeUpdate = () => setCurrentTime(video.currentTime); const handleDurationChange = () => setDuration(video.duration); const handlePlay = () => setIsPlaying(true); const handlePause = () => setIsPlaying(false); video.addEventListener('timeupdate', handleTimeUpdate); video.addEventListener('durationchange', handleDurationChange); video.addEventListener('play', handlePlay); video.addEventListener('pause', handlePause); return () => { video.removeEventListener('timeupdate', handleTimeUpdate); video.removeEventListener('durationchange', handleDurationChange); video.removeEventListener('play', handlePlay); video.removeEventListener('pause', handlePause); }; }, []); const togglePlay = () => { const video = videoRef.current; if (!video) return; if (isPlaying) { video.pause(); } else { video.play(); } }; const handleSeek = (e: React.ChangeEvent) => { const video = videoRef.current; if (!video) return; video.currentTime = parseFloat(e.target.value); }; const skipBackward = () => { const video = videoRef.current; if (!video) return; video.currentTime = Math.max(0, video.currentTime - 5); }; const skipForward = () => { const video = videoRef.current; if (!video) return; video.currentTime = Math.min(duration, video.currentTime + 5); }; const handleDownload = () => { const link = document.createElement('a'); link.href = src; link.download = downloadFilename; link.click(); }; return (
{/* Header */}

{title}

{archiveId && ( )}
{/* Video */}
{/* Timelapse Editor Modal */} {showEditor && archiveId && ( setShowEditor(false)} onSave={onEdit} /> )}
); }