import { Box, Typography } from "@mui/material";
import CustomCheckbox from "@ui_kit/CustomCheckbox";
import InfoIcon from "../../../assets/icons/InfoIcon";
import CustomTextField from "@ui_kit/CustomTextField";
import { questionStore, updateQuestionsList } from "@root/questions";

interface Props {
  totalIndex: number;
}

export default function ResponseSettings({ totalIndex }: Props) {
  const { listQuestions } = questionStore();

  return (
    <Box sx={{ display: "flex" }}>
      <Box sx={{ padding: "20px", display: "flex", flexDirection: "column" }}>
        <Typography>Настройки ответов</Typography>
        <CustomCheckbox
          label={"Длинный текстовый ответ"}
          checked={listQuestions[totalIndex].content.largeCheck}
          handleChange={(e) => {
            let clonContent = listQuestions[totalIndex].content;
            clonContent.largeCheck = e.target.checked;

            if (!e.target.checked) {
              clonContent.large = "";
            }

            updateQuestionsList(totalIndex, { content: clonContent });
          }}
        />
        {listQuestions[totalIndex].content.largeCheck && (
          <CustomTextField
            placeholder={"Развёрнутый ответ"}
            text={listQuestions[totalIndex].content.large}
            onChange={({ target }) => {
              let clonContent = listQuestions[totalIndex].content;
              clonContent.large = target.value;
              updateQuestionsList(totalIndex, { content: clonContent });
            }}
          />
        )}
        <CustomCheckbox
          label={"Можно несколько"}
          checked={listQuestions[totalIndex].content.multi}
          handleChange={(e) => {
            let clonContent = listQuestions[totalIndex].content;
            clonContent.multi = e.target.checked;
            updateQuestionsList(totalIndex, { content: clonContent });
          }}
        />
        <CustomCheckbox
          label={'Вариант "свой ответ"'}
          checked={listQuestions[totalIndex].content.own}
          handleChange={(e) => {
            let clonContent = listQuestions[totalIndex].content;
            clonContent.own = e.target.checked;
            updateQuestionsList(totalIndex, { content: clonContent });
          }}
        />
      </Box>
      <Box sx={{ padding: "20px", display: "flex", flexDirection: "column" }}>
        <Typography>Настройки вопросов</Typography>
        <CustomCheckbox
          label={"Необязательный вопрос"}
          checked={!listQuestions[totalIndex].required}
          handleChange={(e) => {
            updateQuestionsList(totalIndex, { required: !e.target.checked });
          }}
        />
        <Box sx={{ display: "flex" }}>
          <CustomCheckbox
            label={"Внутреннее название вопроса"}
            checked={listQuestions[totalIndex].content.innerNameCheck}
            handleChange={(e) => {
              let clonContent = listQuestions[totalIndex].content;
              clonContent.innerNameCheck = e.target.checked;

              if (!e.target.checked) {
                clonContent.innerName = "";
              }

              updateQuestionsList(totalIndex, { content: clonContent });
            }}
          />{" "}
          <InfoIcon />
        </Box>
        {listQuestions[totalIndex].content.innerNameCheck && (
          <CustomTextField
            placeholder={"Развёрнутое описание вопроса"}
            text={listQuestions[totalIndex].content.innerName}
            onChange={({ target }) => {
              let clonContent = listQuestions[totalIndex].content;
              clonContent.innerName = target.value;
              updateQuestionsList(totalIndex, { content: clonContent });
            }}
          />
        )}
      </Box>
    </Box>
  );
}
