"use client" import { useState, useRef, useEffect } from "react"; import { AnimatePresence, motion } from "framer-motion"; import { useGUCStore } from "@/lib/store"; interface Message { id: string; text: string; sender: "user" | "doctor"; } interface DoctorChatProps { onSend: (message: string) => Promise; } const suggestions = [ "क्या मैं चावल खा सकता हूँ?", "मुझे क्या खाना चाहिए?", "यह कितना गंभीर है?", ]; const BouncingDots = () => (
{[0, 1, 2].map((i) => ( ))}
); const DoctorChat: React.FC = ({ onSend }) => { const { profile } = useGUCStore() const language = profile.language === "HI" ? "hindi" : "english" const [open, setOpen] = useState(false); const [messages, setMessages] = useState([]); const [input, setInput] = useState(""); const [loading, setLoading] = useState(false); const bottomRef = useRef(null); useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages, loading]); const send = async (text: string) => { if (!text.trim() || loading) return; const userMsg: Message = { id: Date.now().toString(), text, sender: "user" }; setMessages((prev) => [...prev, userMsg]); setInput(""); setLoading(true); try { const reply = await onSend(text); setMessages((prev) => [ ...prev, { id: (Date.now() + 1).toString(), text: reply, sender: "doctor" }, ]); } catch { setMessages((prev) => [ ...prev, { id: (Date.now() + 1).toString(), text: "कुछ गड़बड़ हो गई। कृपया दोबारा कोशिश करें।", sender: "doctor", }, ]); } finally { setLoading(false); } }; return ( <> {open && ( <> setOpen(false)} />
🩺
Dr. Raahat

Aapka AI Doctor • Online

{messages.length === 0 && !loading && (

{language === "hindi" ? "कुछ पूछें:" : "Ask something:"}

{suggestions.map((s) => ( ))}
)} {messages.map((msg) => (
{msg.text}
))} {loading && }
setInput(e.target.value)} onKeyDown={(e) => e.key === "Enter" && send(input)} placeholder={ language === "hindi" ? "अपना सवाल लिखें..." : "Type your question..." } className="flex-1 rounded-xl px-4 py-2.5 text-sm outline-none transition-all" style={{ background: "rgba(255,255,255,0.05)", color: "rgba(255,255,255,0.9)", border: "2px solid transparent", }} onFocus={(e) => (e.currentTarget.style.borderColor = "rgba(255,153,51,0.5)")} onBlur={(e) => (e.currentTarget.style.borderColor = "transparent")} />
)} ); }; export default DoctorChat;