import React, { useState, useEffect, useRef } from 'react'; import { useChatbot } from '../../contexts/ChatbotContext'; import './ChatbotInterface.css'; const ChatbotInterface = ({ isVisible, onClose }) => { const { messages, isLoading, error, sendMessage } = useChatbot(); const [inputValue, setInputValue] = useState(''); const messagesEndRef = useRef(null); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); }; useEffect(() => { scrollToBottom(); }, [messages]); const handleSend = () => { if (!inputValue.trim() || isLoading) return; sendMessage(inputValue); setInputValue(''); }; const handleKeyPress = (e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); } }; if (!isVisible) return null; return (