import { useEffect, useRef, useState } from 'react'; import { AnimatePresence, motion } from 'framer-motion'; import { ArrowUp, Loader2, Sparkles, X } from 'lucide-react'; import useChatStore from '../../store/useChatStore'; const QUICK_PROMPTS = [ { text: 'ARR by segment this quarter', label: 'ARR' }, { text: 'Churn risk with open P1 tickets', label: 'Churn' }, { text: 'Slowest SQL executions this week', label: 'Performance' }, ]; export default function Composer({ onSubmit }) { const isSending = useChatStore(s => s.isSending); const [value, setValue] = useState(''); const [isFocused, setIsFocused] = useState(false); const textareaRef = useRef(null); useEffect(() => { const ta = textareaRef.current; if (!ta) return; ta.style.height = 'auto'; ta.style.height = `${Math.min(ta.scrollHeight, 150)}px`; }, [value]); useEffect(() => { const handler = (e) => { setValue(e.detail.query); textareaRef.current?.focus(); }; window.addEventListener('plainsql:submit', handler); return () => window.removeEventListener('plainsql:submit', handler); }, []); const handleSubmit = (e) => { e?.preventDefault(); const q = value.trim(); if (!q || isSending) return; onSubmit(q); setValue(''); if (textareaRef.current) textareaRef.current.style.height = 'auto'; }; const canSend = value.trim().length > 0 && !isSending; return (
{/* Quick prompts */}
{isSending && ( Analyzing... )} {QUICK_PROMPTS.map(prompt => ( ))}