import React, { useState, useEffect } from 'react'; import { InformationCircleIcon } from '@heroicons/react/24/outline'; import { useTranscriptionStore } from '../stores/transcriptionStore'; import { formatTime } from '../utils/subtitleUtils'; const DEFAULT_MERGE_THRESHOLD = 2; const MediaEditControls: React.FC = () => { const [mergeThreshold, setMergeThreshold] = useState(DEFAULT_MERGE_THRESHOLD); const { transcription, currentTime, activeSegmentIndex, currentSegments, undo, redo, canUndo, canRedo, mergeSegmentsByProximity, } = useTranscriptionStore(); const MAX_MERGE_INTERVAL_SECONDS = 30; if (!transcription) { return null; } const displaySegments = currentSegments || transcription.aligned_segments; // Handle merge threshold changes useEffect(() => { mergeSegmentsByProximity(mergeThreshold); }, [mergeThreshold, mergeSegmentsByProximity]); // Keyboard shortcuts for undo/redo useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if ((e.ctrlKey || e.metaKey) && e.key === 'z' && !e.shiftKey) { e.preventDefault(); undo(); } else if ((e.ctrlKey || e.metaKey) && (e.key === 'y' || (e.key === 'z' && e.shiftKey))) { e.preventDefault(); redo(); } }; document.addEventListener('keydown', handleKeyDown); return () => document.removeEventListener('keydown', handleKeyDown); }, [undo, redo]); return (
{/* Current Status Info */}
{formatTime(currentTime)} / {formatTime(transcription.total_duration)} {activeSegmentIndex !== null ? `Segment ${activeSegmentIndex + 1}/${displaySegments.length}` : "No active segment"}
{/* Combine Segments Slider */}
setMergeThreshold(Number(e.target.value))} className="w-20 h-1 bg-gray-600 rounded-lg appearance-none cursor-pointer slider" style={{ background: `linear-gradient(to right, #3B82F6 0%, #3B82F6 ${(mergeThreshold / MAX_MERGE_INTERVAL_SECONDS) * 100}%, #4B5563 ${(mergeThreshold / MAX_MERGE_INTERVAL_SECONDS) * 100}%, #4B5563 100%)` }} />
{/* Undo/Redo Buttons */}
); }; export default MediaEditControls;