import { AnimatePresence, motion } from 'framer-motion'; import { useCallback, useMemo, useState } from 'react'; import { useChatbot } from '@/hooks/features/useChatbot.ts'; import { useTranslation } from '@/hooks/useI18n.tsx'; import { MessageSquare, Trash2, X } from 'lucide-react'; import Button from '@/components/ui/Button.tsx'; import ChatHistory from '@/components/chatbot/ChatHistory.tsx'; import ChatInput from '@/components/chatbot/ChatInput.tsx'; const useCopyToClipboard = () => { const [copiedText, setCopiedText] = useState(null); const copy = useCallback(async (text: string) => { if (!navigator?.clipboard) { console.warn('Clipboard not supported'); return false; } try { await navigator.clipboard.writeText(text); setCopiedText(text); setTimeout(() => setCopiedText(null), 2000); return true; } catch (error) { console.warn('Copy failed', error); setCopiedText(null); return false; } }, []); return { copiedText, copy }; }; const Chatbot = () => { const { t } = useTranslation(); const chatbot = useChatbot(); const { copiedText, copy } = useCopyToClipboard(); // Memoize suggested prompts to prevent recreation const suggestedPrompts = useMemo( () => [t('chatbot.prompt1'), t('chatbot.prompt2'), t('chatbot.prompt3')], [t] ); const handleSuggestionClick = useCallback( (prompt: string) => { chatbot.setInputValue(prompt); chatbot.handleSendMessage(); }, [chatbot] ); return ( <> {chatbot.isOpen && ( {/* Header */}
{t('chatbot.aiAcronym')}

{t('chatbot.header')}

{t('chatbot.online')}

{chatbot.showSuggestions && (
{suggestedPrompts.map((prompt, i) => ( ))}
)} chatbot.setAttachedImage(null)} onFileChange={chatbot.handleFileChange} fileInputRef={chatbot.fileInputRef} inputRef={chatbot.inputRef} isListening={chatbot.isListening} onStartListening={chatbot.startListening} onStopListening={chatbot.stopListening} isSpeechSupported={chatbot.isSpeechSupported} isLoading={chatbot.isLoading} />
)}
); }; export default Chatbot;