import {Exercise, FillBlanksExercise, MatchSentencesExercise, MultipleChoiceExercise, WriteBlanksExercise, WritingExercise} from "@/interfaces/exam";
import dynamic from "next/dynamic";
import FillBlanks from "./FillBlanks";
import MultipleChoice from "./MultipleChoice";
import WriteBlanks from "./WriteBlanks";
import Writing from "./Writing";

const MatchSentences = dynamic(() => import("@/components/Solutions/MatchSentences"), {ssr: false});

export interface CommonProps {
	onNext: () => void;
	onBack: () => void;
}

export const renderSolution = (exercise: Exercise, onNext: () => void, onBack: () => void) => {
	switch (exercise.type) {
		case "fillBlanks":
			return <FillBlanks {...(exercise as FillBlanksExercise)} onNext={onNext} onBack={onBack} />;
		case "matchSentences":
			return <MatchSentences {...(exercise as MatchSentencesExercise)} onNext={onNext} onBack={onBack} />;
		case "multipleChoice":
			return <MultipleChoice {...(exercise as MultipleChoiceExercise)} onNext={onNext} onBack={onBack} />;
		case "writeBlanks":
			return <WriteBlanks {...(exercise as WriteBlanksExercise)} onNext={onNext} onBack={onBack} />;
		case "writing":
			return <Writing {...(exercise as WritingExercise)} onNext={onNext} onBack={onBack} />;
	}
};
