import { WriteBlanksExercise } from "@/interfaces/exam";
import ExerciseLabel from "../../Shared/ExerciseLabel";
import WriteBlanksForm from "../../Exercises/WriteBlanksForm";
import WriteBlanksFill from "../../Exercises/Blanks/WriteBlankFill";
import WriteBlanks from "../../Exercises/WriteBlanks";
import ExerciseItem from "./types";

const writeBlanks = (exercise: WriteBlanksExercise, index: number, sectionId: number): ExerciseItem => {
    const firstQuestionId = exercise.solutions[0].id;
    const lastQuestionId = exercise.solutions[exercise.solutions.length - 1].id;

    switch (exercise.variant) {
        case 'form':
            return {
                id: index.toString(),
                sectionId,
                label: (
                    <ExerciseLabel
                        type='Write Blanks: Form'
                        firstId={firstQuestionId}
                        lastId={lastQuestionId}
                        prompt={exercise.prompt}
                    />
                ),
                content: <WriteBlanksForm exercise={exercise} sectionId={sectionId} />
            };
        case 'fill':
            return {
                id: index.toString(),
                sectionId,
                label: (
                    <ExerciseLabel
                        type='Write Blanks: Fill'
                        firstId={firstQuestionId}
                        lastId={lastQuestionId}
                        prompt={exercise.prompt}
                    />
                ),
                content: <WriteBlanksFill exercise={exercise} sectionId={sectionId} />
            };
        default:
            return {
                id: index.toString(),
                sectionId,
                label: (
                    <ExerciseLabel
                        type='Write Blanks: Questions'
                        firstId={firstQuestionId}
                        lastId={lastQuestionId}
                        prompt={exercise.prompt}
                    />
                ),
                content: <WriteBlanks exercise={exercise} sectionId={sectionId} />
            };
    }
};

export default writeBlanks;
