import React, { useState, useRef, useEffect } from 'react'; import { MessageSquare, X, Send, Terminal } from 'lucide-react'; interface Message { id: string; text: string; sender: 'user' | 'bot'; timestamp: Date; } export const ChatWidget: React.FC = () => { const [isOpen, setIsOpen] = useState(false); const [messages, setMessages] = useState([ { id: '1', text: "System online. I am Pradit's automated assistant. How can I help you engineer your next AI system?", sender: 'bot', timestamp: new Date() } ]); const [input, setInput] = useState(""); const bottomRef = useRef(null); useEffect(() => { if (isOpen) { bottomRef.current?.scrollIntoView({ behavior: 'smooth' }); } }, [messages, isOpen]); const handleSend = async (e: React.FormEvent) => { e.preventDefault(); if (!input.trim()) return; const userMsg: Message = { id: Date.now().toString(), text: input, sender: 'user', timestamp: new Date() }; setMessages(prev => [...prev, userMsg]); setInput(""); // Mock response setTimeout(() => { const botMsg: Message = { id: (Date.now() + 1).toString(), text: "ACK. Request received. Our engineers are currently optimizing a training run. Please visit 'Hire Us' to schedule a deep dive consultation.", sender: 'bot', timestamp: new Date() }; setMessages(prev => [...prev, botMsg]); }, 800); }; return (
{/* Chat Window */} {isOpen && (
{/* Header */}
Pradit/Assistant
{/* Messages */}
{messages.map((msg) => (
{msg.text}
))}
{/* Input */}
{">"} setInput(e.target.value)} placeholder="Type your query..." className="flex-grow bg-transparent text-sm outline-none text-ink placeholder:text-gray-400 font-sans" />
)} {/* Toggle Button */} {!isOpen && ( )}
); };