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

import CustomTextField from "@ui_kit/CustomTextField";

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

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

type TextProps = {
  stepNumber: number;
  question: QuizQuestionText;
};

export const Text = ({ stepNumber, question }: TextProps) => {
  const { answers } = useQuizViewStore();
  const { answer } = answers.find(({ step }) => step === stepNumber) ?? {};

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