import { marked } from "marked";
import DOMPurify from "dompurify";
import { useEffect, useState } from "react";
import BotIcon from "./icons/BotIcon";
import UserIcon from "./icons/UserIcon";
import "./Chat.css";
function render(text) {
return DOMPurify.sanitize(marked.parse(text));
}
// مكون فرعي لكل رسالة للتحكم في التقييم والاقتراحات
function MessageItem({ msg }) {
const [feedback, setFeedback] = useState(null); // 'up' or 'down'
const [showOptions, setShowOptions] = useState(false);
const medicalOptions = [
"Not medically accurate",
"Does not follow ABCDE protocol",
"Too long for emergency context",
"Incorrect dosage suggestion",
"Other medical reason"
];
const handleOptionClick = (option) => {
alert(`Thank you for your feedback: "${option}". This helps improve the ER Assistant.`);
setShowOptions(false);
setFeedback('down');
};
return (
{msg.role === "assistant" ? (
<>
{msg.content.length > 0 ? (
) : (
)}
{/* أزرار التقييم - تظهر فقط بعد انتهاء الكتابة */}
{msg.content.length > 0 && (
{/* نافذة الأسباب (Popup) */}
{showOptions && (
What went wrong?
{medicalOptions.map((option) => (
))}
)}
{feedback === 'up' &&
Feedback sent!}
)}
>
) : (
<>
>
)}
);
}
export default function Chat({ messages }) {
const empty = messages.length === 0;
useEffect(() => {
if (window.MathJax) {
window.MathJax.typeset();
}
}, [messages]);
return (
{empty ? (
ER Assistant is Ready...
) : (
messages.map((msg, i) => (
))
)}
);
}