import { useRef } from "react"; import { useSpeech } from "../hooks/useSpeech"; import { useAuth } from "../contexts/AuthContext"; import { useNavigate } from "react-router-dom"; export const ChatInterface = ({ hidden, ...props }) => { const input = useRef(); const { tts, loading, message, startRecording, stopRecording, recording } = useSpeech(); const { currentUser, logout } = useAuth(); const navigate = useNavigate(); const handleLogout = async () => { try { await logout(); navigate("/login"); } catch (error) { console.error("Failed to log out", error); } }; const sendMessage = () => { const text = input.current.value; const userId = currentUser ? currentUser.uid : "demo_user_123"; if (!loading && !message) { tts(text, userId); input.current.value = ""; } }; if (hidden) { return null; } return (
{loading ? "Thinking..." : "Your AI Medical Assistant"}