'use client'; import { useEffect, useMemo, useState } from 'react'; import { Button, CloseButton, Drawer, Portal, Icon, Textarea, Timeline, HStack, Stack, Text, Alert, SkeletonCircle, SkeletonText, } from '@chakra-ui/react'; import { GiArtificialHive } from 'react-icons/gi'; import { useAiChatStore, useFilters } from '#store'; import { Message } from './Message'; export const AiDrawer = () => { const [open, setOpen] = useState(false); const [input, setInput] = useState(''); const { filters } = useFilters(); const getChat = useAiChatStore((s) => s.getChat); const loadHistory = useAiChatStore((s) => s.loadHistory); const sendPrompt = useAiChatStore((s) => s.sendPrompt); const sendQuickCommand = useAiChatStore((s) => s.sendQuickCommand); const chat = getChat(filters.symbol); const { loading, sending, error, messages } = chat; const isBusy = loading || sending; const canSend = useMemo( () => input.trim().length > 0 && !sending, [input, sending], ); useEffect(() => { void loadHistory(filters.symbol); }, [filters.symbol, loadHistory]); const handleSend = async () => { if (!input.trim()) return; await sendPrompt(filters, input); setInput(''); }; const handleQuick = async (command: string) => { await sendQuickCommand(filters, command); }; return ( setOpen(e.open)} size={'lg'}> AI assistant {error ? ( AI chat error {error} ) : null} {loading ? ( ) : ( {messages.map((message, index) => ( ))} )}