"use client"; import React, { useState, useRef, useCallback, useEffect } from "react"; import { useTheme } from "next-themes"; import { Upload, Paperclip, Send, Moon, Sun, X, FileText, ImageIcon, Video, Music, Archive, MessageCircle, Bot, User, Info, Lock, Mic, AudioLines, Plus, } from "lucide-react"; const API_ENDPOINT = "https://n8n.jonasbomfim.store/webhook/zoe2"; const FALLBACK_RESPONSE = "Tive um problema para responder agora. Tente novamente em alguns instantes."; const FileUploadChat = ({ onOpenVoice }: { onOpenVoice?: () => void }) => { // Usa tema global fornecido por next-themes const { theme, setTheme } = useTheme(); const isDarkMode = theme === "dark"; const [messages, setMessages] = useState([ { id: 1, type: "ai", content: "Compartilhe uma dúvida, exame ou orientação que deseja revisar. A Zoe registra o pedido e te retorna com um resumo organizado para a equipe de saúde.", timestamp: new Date(), }, ]); const [inputValue, setInputValue] = useState(""); const [uploadedFiles, setUploadedFiles] = useState([]); const [isDragOver, setIsDragOver] = useState(false); const [isTyping, setIsTyping] = useState(false); const fileInputRef = useRef(null); const chatEndRef = useRef(null); const textareaRef = useRef(null); // Placeholder responsivo (não quebra, adapta o texto) const [responsivePlaceholder, setResponsivePlaceholder] = useState("Pergunte qualquer coisa para a Zoe"); const computePlaceholder = (w: number) => { if (w < 340) return "Pergunte à Zoe"; // ultra pequeno if (w < 400) return "Pergunte algo à Zoe"; // pequeno if (w < 520) return "Pergunte algo para a Zoe"; // médio estreito return "Pergunte qualquer coisa para a Zoe"; // normal }; useEffect(() => { const update = () => setResponsivePlaceholder(computePlaceholder(window.innerWidth)); update(); window.addEventListener("resize", update); return () => window.removeEventListener("resize", update); }, []); useEffect(() => { chatEndRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages]); useEffect(() => { if (textareaRef.current) { textareaRef.current.style.height = "auto"; textareaRef.current.style.height = textareaRef.current.scrollHeight + "px"; } }, [inputValue]); const getFileIcon = (fileName: string) => { const ext = fileName.split(".").pop()?.toLowerCase(); if (["jpg", "jpeg", "png", "gif", "webp", "svg"].includes(ext || "")) return