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

import CustomTextField from "@ui_kit/CustomTextField";
import ButtonsOptions from "../ButtonsOptions";
import SwitchTextField from "./switchTextField";

import { questionStore, updateQuestionsList } from "@root/questions";

import InfoIcon from "../../../assets/icons/InfoIcon";

import type { ChangeEvent } from "react";

interface Props {
  totalIndex: number;
}
export default function OwnTextField({ totalIndex }: Props) {
  const [switchState, setSwitchState] = useState("setting");
  const { listQuestions } = questionStore();
  const theme = useTheme();

  const SSHC = (data: string) => {
    setSwitchState(data);
  };

  return (
    <>
      <Box
        sx={{
          width: "100%",
          maxWidth: "640px",
          display: "flex",
          padding: "20px",
          flexDirection: "column",
          gap: "20px",
        }}
      >
        <CustomTextField
          placeholder={"Пример ответа"}
          text={listQuestions[totalIndex].content.placeholder}
          onChange={({ target }: ChangeEvent<HTMLInputElement>) => {
            const clonContent = listQuestions[totalIndex].content;
            clonContent.placeholder = target.value;
            updateQuestionsList(totalIndex, { content: clonContent });
          }}
        />
        <Box sx={{ display: "flex", alignItems: "center", gap: "12px" }}>
          <Typography
            sx={{
              fontWeight: 400,
              fontSize: "16px",
              lineHeight: "18.96px",
              color: theme.palette.grey2.main,
            }}
          >
            Пользователю будет дано поле для ввода значения{" "}
          </Typography>
          <InfoIcon />
        </Box>
      </Box>
      <ButtonsOptions
        switchState={switchState}
        SSHC={SSHC}
        totalIndex={totalIndex}
      />
      <SwitchTextField switchState={switchState} totalIndex={totalIndex} />
    </>
  );
}
