import React, { useState, useRef, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Send, Bot, User as UserIcon, X, Loader2 } from 'lucide-react'; import { ChatMessage, UserRole, AppSettings, CalendarEvent } from '../types'; import { generateChatResponse } from '../services/aiService'; interface AssistantViewProps { isOpen: boolean; onClose: () => void; currentUser: UserRole; settings: AppSettings; onEventCreated: (event: CalendarEvent) => void; } export const AssistantView: React.FC = ({ isOpen, onClose, currentUser, settings, onEventCreated }) => { const [input, setInput] = useState(''); const [isLoading, setIsLoading] = useState(false); const [messages, setMessages] = useState([ { id: 'welcome', role: 'assistant', content: `Hi ${currentUser === 'mom' ? 'Mom' : 'Dad'}! I am your cosmic assistant. How can I help you plan?`, timestamp: new Date() } ]); const messagesEndRef = useRef(null); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }; useEffect(() => { scrollToBottom(); }, [messages, isOpen]); const handleSend = async (e?: React.FormEvent) => { e?.preventDefault(); if (!input.trim() || isLoading) return; const userMsg: ChatMessage = { id: Date.now().toString(), role: 'user', content: input, timestamp: new Date() }; setMessages(prev => [...prev, userMsg]); setInput(''); setIsLoading(true); const { text, event } = await generateChatResponse(input, settings, currentUser); const assistantMsg: ChatMessage = { id: (Date.now() + 1).toString(), role: 'assistant', content: text, timestamp: new Date() }; setMessages(prev => [...prev, assistantMsg]); setIsLoading(false); if (event) { onEventCreated(event); } }; return ( {isOpen && ( <> {/* Backdrop */} {/* Side Panel */} {/* Header */}

Home Assistant

{settings.aiProvider === 'ollama' ? 'Local Spirit' : 'Gemini Cloud'}
{/* Chat Area */}
{messages.map((msg) => (
{msg.role === 'user' ? : }
{msg.content}
{msg.timestamp.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
))} {isLoading && (
Consulting the stars...
)}
{/* Input Area */}
setInput(e.target.value)} placeholder="Schedule a date on Friday at 7pm..." className="w-full bg-gray-800 text-white pl-4 pr-12 py-3 rounded-xl border border-gray-700 focus:border-purple-500 focus:ring-1 focus:ring-purple-500 outline-none placeholder-gray-500 transition-all" disabled={isLoading} />
)} ); };