import { Box } from "@mui/material";

import { Variant } from "./questions/Variant";
import { Images } from "./questions/Images";
import { Varimg } from "./questions/Varimg";
import { Emoji } from "./questions/Emoji";
import { Text } from "./questions/Text";
import { Select } from "./questions/Select";
import { Date } from "./questions/Date";
import { Number } from "./questions/Number";
import { File } from "./questions/File";
import { Page } from "./questions/Page";
import { Rating } from "./questions/Rating";
import { Footer } from "./Footer";

import { useState, type FC } from "react";
import type { QuestionType } from "../../model/question/question";
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
import { useCurrentQuiz } from "@root/quizes/hooks";
 import { getQuestionByContentId } from "@root/questions/actions";

type QuestionProps = {
  stepNumber: number;
  setStepNumber: (step: number) => void;
  questions: AnyTypedQuizQuestion[];
};

const QUESTIONS_MAP: any = {
  variant: Variant,
  images: Images,
  varimg: Varimg,
  emoji: Emoji,
  text: Text,
  select: Select,
  date: Date,
  number: Number,
  file: File,
  page: Page,
  rating: Rating,
};

export const Question = ({
  questions,
}: QuestionProps) => {
  const quiz = useCurrentQuiz();
  const [currentQuestion, setCurrentQuestion] = useState(getQuestionByContentId(quiz?.config.haveRoot || ""))
  if (!currentQuestion) return <>не смог отобразить вопрос</>

  const QuestionComponent =
    QUESTIONS_MAP[currentQuestion.type as Exclude<QuestionType, "nonselected">];

  return (
    <Box>
      <Box
        sx={{
          minHeight: "calc(100vh - 75px)",
          width: "100%",
          maxWidth: "1000px",
          padding: "20px 10px 0",
          margin: "0 auto",
        }}
      >
        <QuestionComponent currentQuestion={currentQuestion}/>
      </Box>
      <Footer
        question={currentQuestion}
        setCurrentQuestion={setCurrentQuestion}
      />
    </Box>
  );
};
