import 'katex/dist/katex.min.css'; import { useState, useEffect } from 'react'; // Import custom hooks import { useDocumentProcessor } from '../hooks/useDocumentProcessor'; import { useChunkNavigation } from '../hooks/useChunkNavigation'; import { usePanelResize } from '../hooks/usePanelResize'; // Import components import LoadingAnimation from './LoadingAnimation'; import DocumentViewer from './DocumentViewer'; import ChunkPanel from './ChunkPanel'; import ProgressBar from './ProgressBar'; function DocumentProcessor() { // State for PDF navigation const [pdfNavigation, setPdfNavigation] = useState(null); // State for first LLM response loading const [waitingForFirstResponse, setWaitingForFirstResponse] = useState(false); // Custom hooks const { fileInputRef, selectedFile, processing, uploadProgress, documentData, handleFileChange, processDocument, setSelectedFile } = useDocumentProcessor(); const { chunkStates, currentChunkIndex, chunkExpanded, showChat, isTransitioning, goToNextChunk, goToPrevChunk, skipChunk, markChunkUnderstood, startInteractiveLesson, setChunkExpanded, setShowChat, setChunkAsInteractive, updateGlobalChatHistory, getGlobalChatHistory, addMessageToChunk, getCurrentChunkMessages, hasChunkMessages, isChunkCompleted, canEditChunk } = useChunkNavigation(documentData, null); const { leftPanelWidth, isDragging, containerRef, handleMouseDown } = usePanelResize(50); // Sync PDF page navigation with chunk switching useEffect(() => { if (pdfNavigation && documentData && documentData.chunks[currentChunkIndex]) { const currentChunk = documentData.chunks[currentChunkIndex]; if (currentChunk.page && pdfNavigation.goToPage) { pdfNavigation.goToPage(currentChunk.page); } } }, [currentChunkIndex, pdfNavigation, documentData]); // Simplified startInteractiveLesson const handleStartInteractiveLesson = () => { startInteractiveLesson(); }; // Early returns for different states if (!selectedFile) { return (