import React, { useEffect, useRef } from 'react'; import { AlignedSegment } from '../services/transcriptionApi'; import { formatTime } from '../utils/subtitleUtils'; interface SegmentEditorProps { segment: AlignedSegment; segmentIndex: number; onUpdateText: (index: number, text: string) => void; onDeleteSegment: (index: number) => void; onClose: () => void; } export default function SegmentEditor({ segment, segmentIndex, onUpdateText, onDeleteSegment, onClose, }: SegmentEditorProps) { const textareaRef = useRef(null); useEffect(() => { // Focus the textarea when component mounts if (textareaRef.current) { textareaRef.current.focus(); textareaRef.current.select(); } }, []); const handleTextChange = (e: React.ChangeEvent) => { const newText = e.target.value; onUpdateText(segmentIndex, newText); }; const handleDelete = () => { onDeleteSegment(segmentIndex); onClose(); }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Escape') { e.preventDefault(); onClose(); } }; return (

Edit Segment #{segmentIndex + 1}

{formatTime(segment.start)} - {formatTime(segment.end)} ({segment.duration.toFixed(1)}s)