import { useState, useRef, useEffect } from 'react'; import './ChatPanel.css'; /** * ChatPanel * * Layer 3: Interaction (Utility Layer) * Handles live conversation and input. */ function ChatPanel({ messages, onSendMessage, onNewChat, userAvatar, isTyping, onInputStateChange }) { const [input, setInput] = useState(''); const scrollRef = useRef(null); // Auto-scroll to bottom on new messages useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [messages, isTyping]); const handleInputChange = (e) => { const val = e.target.value; setInput(val); if (onInputStateChange) { onInputStateChange(val.length > 0); } }; const handleSubmit = (e) => { e.preventDefault(); if (!input.trim() || isTyping) return; onSendMessage(input); setInput(''); if (onInputStateChange) onInputStateChange(false); }; return (
{messages.length === 0 && (
lens_blur

Neural Core Initialized.

Feed me a thought to begin building your neural pathways.

)} {messages.map((msg, i) => (
{msg.role === 'user' ? ( User ) : ( lens_blur )}
{msg.role === 'user' ? 'You' : 'Soma'}
{msg.content}
{msg.timestamp}
))} {isTyping && messages.length > 0 && messages[messages.length - 1].role === 'user' && (
lens_blur
)}
); } export default ChatPanel;