import React, { useState, useRef, useEffect } from 'react'; import { Button } from '../ui/button'; import { Send } from 'lucide-react'; interface Message { role: 'user' | 'assistant'; content: string; } export default function AIChat() { const [messages, setMessages] = useState([]); const [input, setInput] = useState(''); const chatContainerRef = useRef(null); useEffect(() => { if (chatContainerRef.current) { chatContainerRef.current.scrollTop = chatContainerRef.current.scrollHeight; } }, [messages]); const handleSend = async () => { if (input.trim() === '') return; const newMessage: Message = { role: 'user', content: input }; setMessages(prev => [...prev, newMessage]); setInput(''); // TODO: Implement actual API call to LLM here // For now, we'll just simulate a response setTimeout(() => { const assistantMessage: Message = { role: 'assistant', content: 'This is a simulated response from the AI.' }; setMessages(prev => [...prev, assistantMessage]); }, 1000); }; return (
{messages.map((message, index) => (
{message.content}
))}
setInput(e.target.value)} onKeyPress={(e) => e.key === 'Enter' && handleSend()} className="flex-grow p-2 border rounded-lg" placeholder="Type your message..." />
); }