/**
* ChatArea.jsx - Message Display and Input with Select Notes Button
*/
const { useState, useEffect, useRef } = React;
const { MessageBubble } = window;
function ChatArea({ messages, isSending, onSendMessage, selectedNoteCount, onSelectNotes, onFileUpload, pendingFiles = [], onRemovePendingFile, t }) {
const [inputValue, setInputValue] = useState('');
const messagesEndRef = useRef(null);
const textareaRef = useRef(null);
const fileInputRef = useRef(null);
const [isUploading, setIsUploading] = useState(false);
// Auto-scroll to bottom when messages change
useEffect(() => {
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
}, [messages]);
const handleSend = async () => {
if (!inputValue.trim() || isSending) return;
const message = inputValue.trim();
setInputValue('');
// setIsSending(true); // This line was removed in the provided diff, but the original code had it.
// The diff implies that `isSending` is managed by the parent component or `onSendMessage` itself.
// For now, I'll follow the diff and remove it.
await onSendMessage(message);
// try {
// await onSendMessage(message);
// } finally {
// setIsSending(false);
// }
};
const handleKeyDown = (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
handleSend();
}
};
const handleFileChange = async (e) => {
const files = Array.from(e.target.files);
if (files.length === 0) return;
setIsUploading(true);
try {
await onFileUpload(files);
} finally {
setIsUploading(false);
// Reset file input
if (fileInputRef.current) {
fileInputRef.current.value = '';
}
}
};
const handleAttachClick = () => {
fileInputRef.current?.click();
};
return (
{/* Messages Area - Scrollable */}
{messages.length === 0 ? (
☁️
{t('ask.welcomeTitle') || 'Welcome to Ask AI'}
{t('ask.welcomeMessage') || 'Start a new conversation by clicking "New Chat" above. Select your notes and ask questions to get instant AI-powered answers!'}