import {
	Exercise,
	FillBlanksExercise,
	InteractiveSpeakingExercise,
	MatchSentencesExercise,
	MultipleChoiceExercise,
	SpeakingExercise,
	TrueFalseExercise,
	UserSolution,
	WriteBlanksExercise,
	WritingExercise,
} from "@/interfaces/exam";
import dynamic from "next/dynamic";
import FillBlanks from "./FillBlanks";
import InteractiveSpeaking from "./InteractiveSpeaking";
import MultipleChoice from "./MultipleChoice";
import Speaking from "./Speaking";
import TrueFalseSolution from "./TrueFalse";
import WriteBlanks from "./WriteBlanks";
import Writing from "./Writing";

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

export interface CommonProps {
	updateIndex?: (internalIndex: number) => void;
	onNext: (userSolutions: UserSolution) => void;
	onBack: (userSolutions: UserSolution) => void;
}

export const renderSolution = (exercise: Exercise, onNext: () => void, onBack: () => void, updateIndex?: (internalIndex: number) => void) => {
	switch (exercise.type) {
		case "fillBlanks":
			return <FillBlanks {...(exercise as FillBlanksExercise)} onNext={onNext} onBack={onBack} />;
		case "trueFalse":
			return <TrueFalseSolution {...(exercise as TrueFalseExercise)} onNext={onNext} onBack={onBack} />;
		case "matchSentences":
			return <MatchSentences {...(exercise as MatchSentencesExercise)} onNext={onNext} onBack={onBack} />;
		case "multipleChoice":
			return <MultipleChoice {...(exercise as MultipleChoiceExercise)} updateIndex={updateIndex} 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} />;
		case "speaking":
			return <Speaking {...(exercise as SpeakingExercise)} onNext={onNext} onBack={onBack} />;
		case "interactiveSpeaking":
			return <InteractiveSpeaking {...(exercise as InteractiveSpeakingExercise)} onNext={onNext} onBack={onBack} />;
	}
};
