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

import { useQuizViewStore, updateAnswer } from "@root/quizView";

import type { QuizQuestionPage } from "../../../model/questionTypes/page";

type PageProps = {
  currentQuestion: QuizQuestionPage;
};

export const Page = ({ currentQuestion }: PageProps) => {
  const { answers } = useQuizViewStore();
  const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.content.id) ?? {};

  return (
    <Box>
      <Typography variant="h5">{currentQuestion.title}</Typography>
      <Box
        sx={{
          display: "flex",
          flexDirection: "column",
          width: "100%",
          marginTop: "20px",
        }}
      >
        {currentQuestion.content.picture && (
          <img
            src={currentQuestion.content.picture}
            alt=""
            style={{
              display: "block",
              width: "100%",
              height: "100%",
              maxHeight: "80vh",
              objectFit: "contain",
            }}
          />
        )}
        {currentQuestion.content.video && (
          <video
            src={currentQuestion.content.video}
            controls
            style={{
              width: "100%",
              height: "100%",
              maxHeight: "80vh",
              objectFit: "contain",
            }}
          />
        )}
      </Box>
    </Box>
  );
};
