/* eslint-disable @next/next/no-img-element */ import { MultipleChoiceQuestion } from "@/interfaces/exam"; import clsx from "clsx"; import reactStringReplace from "react-string-replace"; import { v4 } from "uuid"; interface Props { userSolution: string | undefined; onSelectOption?: (option: string) => void; showSolution?: boolean; } const Question: React.FC = ({ id, variant, prompt, options, userSolution, onSelectOption, }) => { const renderPrompt = (prompt: string) => { return reactStringReplace(prompt, /(.*?<\/u>)/g, (match) => { const word = match.replaceAll("", "").replaceAll("", ""); return word.length > 0 ? {word} : null; }); }; return (
{isNaN(Number(id)) ? ( {renderPrompt(prompt).filter((x) => x?.toString() !== "")} ) : ( <> {id} - {renderPrompt(prompt).filter((x) => x?.toString() !== "")} )}
{variant === "image" && options.map((option) => (
(onSelectOption ? onSelectOption(option.id.toString()) : null)} className={clsx( "flex flex-col items-center border border-mti-gray-platinum p-4 px-8 rounded-xl gap-4 cursor-pointer bg-white relative select-none", userSolution === option.id.toString() && "border-mti-purple-light", )}> {option.id.toString()} {`Option
))} {variant === "text" && options.map((option) => (
(onSelectOption ? onSelectOption(option.id.toString()) : null)} className={clsx( "flex border p-4 rounded-xl gap-2 cursor-pointer bg-white text-base select-none", userSolution === option.id.toString() && "!bg-mti-purple-light !text-white", )}> {option.id.toString()}. {option.text}
))}
); } export default Question;