import { useEffect, useRef, useState } from "react"; import ChatHeader from "./ChatHeader"; import MessageBubble from "./MessageBubble"; import QuickActions from "./QuickActions"; import ChatInput from "./ChatInput"; interface Message { id: string; text: string; isUser: boolean; timestamp: string; quickActions?: string[]; } const ChatWindow = () => { const [messages, setMessages] = useState([ { id: "1", text: "Hello! I'm your AI assistant. How can I help you today?", isUser: false, timestamp: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }), quickActions: ["Get started", "Learn more", "Contact support"] } ]); const messagesEndRef = useRef(null); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); }; useEffect(() => { scrollToBottom(); }, [messages]); const handleSendMessage = (text: string) => { const newMessage: Message = { id: Date.now().toString(), text, isUser: true, timestamp: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }), }; setMessages(prev => [...prev, newMessage]); // Simulate bot response setTimeout(() => { const botResponse: Message = { id: (Date.now() + 1).toString(), text: "Thank you for your message! I'm processing your request and will provide a helpful response shortly.", isUser: false, timestamp: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }), quickActions: ["Tell me more", "That's helpful", "Start over"] }; setMessages(prev => [...prev, botResponse]); }, 1000); }; const handleQuickAction = (action: string) => { handleSendMessage(action); }; return (
{messages.map((message, index) => (
{message.quickActions && index === messages.length - 1 && ( )}
))}
); }; export default ChatWindow;