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 {
	headerButtons?: React.ReactNode,
	footerButtons?: React.ReactNode,
}

export const renderSolution = (
	exercise: Exercise,
	headerButtons?: React.ReactNode,
	footerButtons?: React.ReactNode,
) => {
	const sharedProps = {
		key: exercise.id,
		headerButtons, 
		footerButtons,
	}
	switch (exercise.type) {
		case "fillBlanks":
			return <FillBlanks {...(exercise as FillBlanksExercise)}  {...sharedProps}/>;
		case "trueFalse":
			return <TrueFalseSolution {...(exercise as TrueFalseExercise)}  {...sharedProps}/>;
		case "matchSentences":
			return <MatchSentences {...(exercise as MatchSentencesExercise)}  {...sharedProps}/>;
		case "multipleChoice":
			return <MultipleChoice {...(exercise as MultipleChoiceExercise)}  {...sharedProps}/>;
		case "writeBlanks":
			return <WriteBlanks {...(exercise as WriteBlanksExercise)}  {...sharedProps}/>;
		case "writing":
			return <Writing {...(exercise as WritingExercise)}  {...sharedProps}/>;
		case "speaking":
			return <Speaking {...(exercise as SpeakingExercise)}  {...sharedProps}/>;
		case "interactiveSpeaking":
			return <InteractiveSpeaking {...(exercise as InteractiveSpeakingExercise)}  {...sharedProps}/>;
	}
};
