import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { Send, Square, Globe, WifiOff, ChevronUp, AlertCircle, GraduationCap, Newspaper, Terminal, TrendingUp } from "lucide-react"; import { useState, useRef, useEffect, useMemo } from "react"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { quickValidate, validateQuery } from "@/lib/query-validation"; import { useSettingsStore, type SearchCategory } from "@/store/settings-store"; interface ChatInputProps { onSend: (message: string) => void; onStop: () => void; isLoading: boolean; webSearchEnabled?: boolean; onWebSearchToggle?: (enabled: boolean) => void; categories?: SearchCategory[]; onToggleCategory?: (id: string, enabled: boolean) => void; } export function ChatInput({ onSend, onStop, isLoading, webSearchEnabled = true, onWebSearchToggle, categories = [], onToggleCategory, }: ChatInputProps) { const [input, setInput] = useState(""); const textareaRef = useRef(null); const [webDialogOpen, setWebDialogOpen] = useState(false); const settings = useSettingsStore(); // Validação em tempo real const validation = useMemo(() => { if (!input.trim()) { return { isValid: true, errors: [], warnings: [] }; } const preprocessingConfig = settings.queryPreprocessing || { enabled: true, minLength: 3, maxLength: 2000, autoSplitQuestions: true, irrelevantPatterns: [], }; if (!preprocessingConfig.enabled) { return { isValid: true, errors: [], warnings: [] }; } return validateQuery(input, { minLength: preprocessingConfig.minLength, maxLength: preprocessingConfig.maxLength, irrelevantPatterns: preprocessingConfig.irrelevantPatterns.length > 0 ? preprocessingConfig.irrelevantPatterns : undefined, }); }, [input, settings.queryPreprocessing]); const isValid = validation.isValid; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); handleSend(); } }; const handleSend = () => { if (input.trim() && !isLoading && isValid) { onSend(input); setInput(""); } }; useEffect(() => { if (textareaRef.current) { textareaRef.current.style.height = "auto"; const scrollHeight = textareaRef.current.scrollHeight; // Limitar altura máxima a uns 200px textareaRef.current.style.height = `${Math.min(scrollHeight, 200)}px`; } }, [input]); return (