import React, { useState, useRef, useEffect } from 'react' export default function ChatPanel({ nodes, messages, onSendMessage, onClose }) { const [input, setInput] = useState('') const [selectedNode, setSelectedNode] = useState(null) const messagesEndRef = useRef(null) const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }) } useEffect(() => { scrollToBottom() }, [messages]) const handleSend = () => { if (!input.trim() || !selectedNode) return onSendMessage(input, selectedNode) setInput('') } const ceoNode = nodes.find(n => n.type === 'ceo') return (
{/* Header */}

Agent Chat

Communicate with your agents

{/* Node Selector */}
{nodes.map((node) => ( ))}
{/* Messages */}
{messages.length === 0 ? (
💬

Select an agent and start chatting

{ceoNode && (

Tip: Use CEO to coordinate between agents

)}
) : ( messages.map((msg) => (
{msg.sender !== 'user' && (

{msg.senderName}

)}

{msg.content}

{new Date(msg.timestamp).toLocaleTimeString()}

)) )}
{/* Input */}
setInput(e.target.value)} onKeyPress={(e) => e.key === 'Enter' && handleSend()} placeholder={selectedNode ? "Type your message..." : "Select an agent first..."} disabled={!selectedNode} className="flex-1 px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white text-sm focus:outline-none focus:ring-2 focus:ring-violet-500 focus:border-transparent disabled:opacity-50 disabled:cursor-not-allowed" />
) }