/**
 * @license
 * SPDX-License-Identifier: Apache-2.0
 */

import React, { useState } from 'react';
import UploadScreen from './components/UploadScreen';
import EditorScreen from './components/EditorScreen';

function App() {
  const [currentView, setCurrentView] = useState<'upload' | 'editor'>('upload');
  const [videoFile, setVideoFile] = useState<File | null>(null);
  const [targetLanguage, setTargetLanguage] = useState<string>('en');
  const [trimRange, setTrimRange] = useState<{start: number, end: number} | null>(null);

  const handleVideoUpload = (file: File, lang: string, startTime?: number, endTime?: number) => {
    setVideoFile(file);
    setTargetLanguage(lang);
    if (startTime !== undefined && endTime !== undefined) {
      setTrimRange({ start: startTime, end: endTime });
    } else {
      setTrimRange(null);
    }
    setCurrentView('editor');
  };

  return (
    <div className="min-h-screen bg-gray-50 text-gray-800 font-sans">
      {currentView === 'upload' ? (
        <UploadScreen onUpload={handleVideoUpload} />
      ) : (
        <EditorScreen 
          videoFile={videoFile} 
          targetLanguage={targetLanguage}
          trimRange={trimRange}
          onBack={() => setCurrentView('upload')} 
        />
      )}
    </div>
  );
}

export default App;
