"use client"; import React, { useState, useRef, useCallback, useEffect } from "react"; import { Upload, Paperclip, Send, Moon, Sun, X, FileText, ImageIcon, Video, Music, Archive, MessageCircle, Bot, User, Info, Lock, Mic, } 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 }) => { const [isDarkMode, setIsDarkMode] = useState(true); 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); // Auto-scroll to bottom when new messages arrive useEffect(() => { chatEndRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages]); // Auto-resize textarea 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