import React, { useState, useRef, useEffect } from "react"; import type { Message } from "../types"; interface ChatPaneProps { messages: Message[]; onSend: (message: string) => void; isLoading: boolean; disabled: boolean; placeholder: string; collapsed: boolean; chatWidth: number; onToggleCollapse: () => void; } export function ChatPane({ messages, onSend, isLoading, disabled, placeholder, collapsed, chatWidth, onToggleCollapse, }: ChatPaneProps) { const [input, setInput] = useState(""); const messagesEndRef = useRef(null); useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages]); const handleSend = () => { if (!input.trim() || isLoading || disabled) return; onSend(input.trim()); setInput(""); }; return (
{!collapsed && Chat}
{!collapsed && ( <>
{messages.map((msg) => (
{msg.content}
))} {isLoading && (
Thinking...
)}
setInput(e.target.value)} onKeyDown={(e) => e.key === "Enter" && !e.shiftKey && handleSend() } placeholder={placeholder} disabled={disabled || isLoading} />
)}
); }