'use client'; import { useState, useRef, useEffect } from 'react'; import { Send, Bot, User, Sparkles, Loader2, X, Maximize2, Minimize2 } from 'lucide-react'; interface Message { id: string; role: 'user' | 'assistant'; content: string; timestamp: Date; } interface AIChatPanelProps { onClose?: () => void; isExpanded?: boolean; onToggleExpand?: () => void; } export default function AIChatPanel({ onClose, isExpanded, onToggleExpand }: AIChatPanelProps) { const [messages, setMessages] = useState([ { id: '1', role: 'assistant', content: "Hello! I'm the QuantumShield AI Assistant. I can help you analyze transactions, understand fraud patterns, and explain how our quantum-enhanced detection works. What would you like to know?", timestamp: new Date() } ]); const [input, setInput] = useState(''); const [isLoading, setIsLoading] = useState(false); const messagesEndRef = useRef(null); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }; useEffect(() => { scrollToBottom(); }, [messages]); const sendMessage = async () => { if (!input.trim() || isLoading) return; const userMessage: Message = { id: Date.now().toString(), role: 'user', content: input, timestamp: new Date() }; setMessages(prev => [...prev, userMessage]); setInput(''); setIsLoading(true); try { const response = await fetch('http://localhost:8000/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: input, conversation_history: messages.map(m => ({ role: m.role, content: m.content })) }) }); if (!response.ok) throw new Error('Chat request failed'); const data = await response.json(); const assistantMessage: Message = { id: (Date.now() + 1).toString(), role: 'assistant', content: data.response, timestamp: new Date() }; setMessages(prev => [...prev, assistantMessage]); } catch (error) { const errorMessage: Message = { id: (Date.now() + 1).toString(), role: 'assistant', content: "I'm having trouble connecting to the server. Please make sure the backend is running on port 8000.", timestamp: new Date() }; setMessages(prev => [...prev, errorMessage]); } finally { setIsLoading(false); } }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendMessage(); } }; const suggestedQuestions = [ "How does quantum detection work?", "What are VQC, QAOA, and QNN?", "Explain the fraud scoring system" ]; return (
{/* Header */}

AI ASSISTANT

Quantum Analysis Expert

{onToggleExpand && ( )} {onClose && ( )}
{/* Messages */}
{messages.map((message) => (
{message.role === 'user' ? ( ) : ( )}

{message.content}

{message.timestamp.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}

))} {isLoading && (
Analyzing...
)}
{/* Suggested Questions */} {messages.length <= 2 && (
{suggestedQuestions.map((question, index) => ( ))}
)} {/* Input */}
setInput(e.target.value)} onKeyPress={handleKeyPress} placeholder="Ask about fraud detection..." className="flex-1 bg-white/10 border-0 rounded-xl px-4 py-3 text-white placeholder-white/40 focus:ring-2 focus:ring-blue-500 focus:outline-none" disabled={isLoading} />
); }