// ChatInterface Component - AI Chat for layout questions import React, { useState, useRef, useEffect } from 'react'; import { Send, Bot, User, Sparkles } from 'lucide-react'; import type { ChatMessage } from '../types'; interface ChatInterfaceProps { messages: ChatMessage[]; onSendMessage: (message: string) => void; loading: boolean; disabled: boolean; } export const ChatInterface: React.FC = ({ messages, onSendMessage, loading, disabled, }) => { const [input, setInput] = useState(''); const messagesEndRef = useRef(null); // Auto-scroll to bottom on new messages useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [messages]); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (input.trim() && !loading && !disabled) { onSendMessage(input.trim()); setInput(''); } }; const suggestedQuestions = [ "What's the difference between the options?", "Which layout do you recommend?", "How does the optimization work?", "What are the compliance requirements?", ]; return (

AI Assistant

{messages.length === 0 ? (

Ask about your layouts

I can help you understand optimization options, metrics, and compliance.

{suggestedQuestions.map((q, i) => ( ))}
) : ( messages.map((msg, index) => (
{msg.role === 'user' ? : }
{msg.content}
{msg.role === 'assistant' && msg.model && (
{msg.model === 'gemini-2.0-flash' ? '🤖 Powered by Gemini' : '💬 Fallback Mode'}
)}
)) )} {loading && (
)}
setInput(e.target.value)} placeholder={disabled ? "Upload a site first..." : "Ask about your layouts..."} disabled={loading || disabled} className="chat-input" />
); }; export default ChatInterface;