import {
	Exercise,
	FillBlanksExercise,
	InteractiveSpeakingExercise,
	MatchSentencesExercise,
	MultipleChoiceExercise,
	SpeakingExercise,
	TrueFalseExercise,
	UserSolution,
	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";
import Speaking from "./Speaking";
import TrueFalse from "./TrueFalse";
import InteractiveSpeaking from "./InteractiveSpeaking";

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

export interface CommonProps {
	examID?: string;
	onNext: (userSolutions: UserSolution) => void;
	onBack: (userSolutions: UserSolution) => void;
}

export const renderExercise = (
	exercise: Exercise,
	examID: string,
	onNext: (userSolutions: UserSolution) => void,
	onBack: (userSolutions: UserSolution) => void,
) => {
	switch (exercise.type) {
		case "fillBlanks":
			return <FillBlanks key={exercise.id} {...(exercise as FillBlanksExercise)} onNext={onNext} onBack={onBack} examID={examID} />;
		case "trueFalse":
			return <TrueFalse key={exercise.id} {...(exercise as TrueFalseExercise)} onNext={onNext} onBack={onBack} examID={examID} />;
		case "matchSentences":
			return <MatchSentences key={exercise.id} {...(exercise as MatchSentencesExercise)} onNext={onNext} onBack={onBack} examID={examID} />;
		case "multipleChoice":
			return <MultipleChoice key={exercise.id} {...(exercise as MultipleChoiceExercise)} onNext={onNext} onBack={onBack} examID={examID} />;
		case "writeBlanks":
			return <WriteBlanks key={exercise.id} {...(exercise as WriteBlanksExercise)} onNext={onNext} onBack={onBack} examID={examID} />;
		case "writing":
			return <Writing key={exercise.id} {...(exercise as WritingExercise)} onNext={onNext} onBack={onBack} examID={examID} />;
		case "speaking":
			return <Speaking key={exercise.id} {...(exercise as SpeakingExercise)} onNext={onNext} onBack={onBack} examID={examID} />;
		case "interactiveSpeaking":
			return (
				<InteractiveSpeaking
					key={exercise.id}
					{...(exercise as InteractiveSpeakingExercise)}
					examID={examID}
					onNext={onNext}
					onBack={onBack}
				/>
			);
	}
};
