import { Question } from "@/types/exam"; import { BookmarkCheck, Bookmark } from "lucide-react"; import React, { useState } from "react"; import { Badge } from "./ui/badge"; interface ResultItemProps { mode: "result"; question: Question; selectedAnswer: string | undefined; } interface ExamItemProps { mode: "exam"; question: Question; selectedAnswer?: string; handleSelect: (questionId: number, option: string) => void; } type QuestionItemProps = ResultItemProps | ExamItemProps; const QuestionItem = (props: QuestionItemProps) => { const [bookmark, setBookmark] = useState(false); const { question, selectedAnswer } = props; const isExam = props.mode === "exam"; return (

{question.id}. {question.question}

{isExam ? (
{Object.entries(question.options).map(([key, value]) => { const isSelected = selectedAnswer === key; return ( ); })}
) : ( <>
{!selectedAnswer ? ( Skipped ) : selectedAnswer.answer === question.correctAnswer ? ( Correct ) : ( Incorrect )}
{Object.entries(question.options).map(([key, value]) => { const isCorrect = key === question.correctAnswer; const isSelected = key === selectedAnswer?.answer; let optionStyle = "px-2 py-1 flex items-center rounded-full border font-medium text-sm"; if (isCorrect) { optionStyle += " bg-green-600 text-white border-green-600"; } if (isSelected && !isCorrect) { optionStyle += " bg-red-600 text-white border-red-600"; } if (!isCorrect && !isSelected) { optionStyle += " border-gray-300 text-gray-700"; } return (
{key.toUpperCase()} {value}
); })}

Solution:

{question.solution}

)}
); }; export default QuestionItem;