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

import CustomTextField from "@ui_kit/CustomTextField";

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

import type { QuizQuestionText } from "../../../model/questionTypes/text";

type TextProps = {
  currentQuestion: QuizQuestionText;
};

export const Text = ({ currentQuestion }: TextProps) => {
  const { answers } = useQuizViewStore();
  const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};

  return (
    <Box>
      <Typography variant="h5">{currentQuestion.title}</Typography>
      <Box
        sx={{
          display: "flex",
          flexDirection: "column",
          width: "100%",
          marginTop: "20px",
        }}
      >
        <CustomTextField
          placeholder={currentQuestion.content.placeholder}
          //@ts-ignore
          value={answer || ""}
          onChange={({ target }) => updateAnswer(currentQuestion.id, target.value)}
        />
      </Box>
    </Box>
  );
};
