import { useState, useEffect, useRef } from 'react'; import ReactMarkdown from 'react-markdown'; import remarkMath from 'remark-math'; import rehypeKatex from 'rehype-katex'; import rehypeRaw from 'rehype-raw'; import { getChatMarkdownComponents } from '../utils/markdownComponents.jsx'; const SimpleChat = ({ messages, currentChunkIndex, canEdit, onSend, isLoading }) => { const [input, setInput] = useState(''); const messagesEndRef = useRef(null); const currentChunkStartRef = useRef(null); const handleSubmit = (e) => { e.preventDefault(); if (!input.trim() || isLoading || !canEdit) return; onSend(input.trim()); setInput(''); }; // Scroll to current chunk's first message when chunk changes useEffect(() => { if (currentChunkStartRef.current) { currentChunkStartRef.current.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }, [currentChunkIndex]); // Find the first message of the current chunk const currentChunkFirstMessageIndex = messages.findIndex(msg => msg.chunkIndex === currentChunkIndex); return (