/* eslint-disable @next/next/no-img-element */ import {errorButtonStyle, infoButtonStyle} from "@/constants/buttonStyles"; import {MultipleChoiceExercise, MultipleChoiceQuestion} from "@/interfaces/exam"; import {mdiArrowLeft, mdiArrowRight, mdiCheck, mdiClose} from "@mdi/js"; import Icon from "@mdi/react"; import clsx from "clsx"; import {useState} from "react"; import {CommonProps} from "."; function Question({ variant, prompt, solution, options, userSolution, onSelectOption, showSolution = false, }: MultipleChoiceQuestion & {userSolution: string | undefined; onSelectOption?: (option: string) => void; showSolution?: boolean}) { const optionColor = (option: string) => { if (!showSolution) { return userSolution === option ? "border-blue-400" : ""; } if (option === solution) { return "border-green-500 text-green-500"; } return userSolution === option ? "border-red-500 text-red-500" : ""; }; const optionBadge = (option: string) => { if (option === userSolution) { if (solution === option) { return (
); } return (
); } }; return (
{prompt}
{variant === "image" && options.map((option) => (
(onSelectOption ? onSelectOption(option.id) : null)} className={clsx( "flex flex-col items-center border-2 p-4 rounded-xl gap-4 cursor-pointer bg-white relative", optionColor(option.id), )}> {showSolution && optionBadge(option.id)} {`Option {option.id}
))} {variant === "text" && options.map((option) => (
(onSelectOption ? onSelectOption(option.id) : null)} className={clsx("flex border-2 p-4 rounded-xl gap-2 cursor-pointer bg-white", optionColor(option.id))}> {showSolution && optionBadge(option.id)} {option.id}. {option.text}
))}
); } export default function MultipleChoice({prompt, questions, userSolutions, onNext, onBack}: MultipleChoiceExercise & CommonProps) { const [questionIndex, setQuestionIndex] = useState(0); const next = () => { if (questionIndex === questions.length - 1) { onNext(); } else { setQuestionIndex((prev) => prev + 1); } }; const back = () => { if (questionIndex === 0) { onBack(); } else { setQuestionIndex((prev) => prev - 1); } }; return ( <>
{prompt} {questionIndex < questions.length && ( questions[questionIndex].id === x.question)?.option} showSolution /> )}
); }