import { Box, Typography, useTheme } from "@mui/material";
import ButtonsOptions from "../ButtonsOptions";
import React from "react";
import CustomTextField from "@ui_kit/CustomTextField";
import SwitchSlider from "./switchSlider";
import { questionStore, updateQuestionsList } from "@root/questions";

interface Props {
  totalIndex: number;
}

export default function SliderOptions({ totalIndex }: Props) {
  const [switchState, setSwitchState] = React.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",
        }}
      >
        <Box sx={{ gap: "10px", display: "flex", flexDirection: "column" }}>
          <Typography>Выбор значения из диапазона</Typography>
          <Box sx={{ display: "flex", alignItems: "center", gap: "20px" }}>
            <CustomTextField
              placeholder={"0"}
              text={listQuestions[totalIndex].content.range.split("—")[0]}
              onChange={({ target }) => {
                const clonContent = listQuestions[totalIndex].content;
                clonContent.range = `${target.value}—${
                  listQuestions[totalIndex].content.range.split("—")[1]
                }`;
                updateQuestionsList(totalIndex, { content: clonContent });
              }}
            />
            <Typography>—</Typography>
            <CustomTextField
              placeholder={"100"}
              text={listQuestions[totalIndex].content.range.split("—")[1]}
              onChange={({ target }) => {
                const clonContent = listQuestions[totalIndex].content;
                clonContent.range = `${
                  listQuestions[totalIndex].content.range.split("—")[0]
                }—${target.value}`;
                updateQuestionsList(totalIndex, { content: clonContent });
              }}
            />
          </Box>
        </Box>
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
            justifyContent: "space-between",
          }}
        >
          <Box>
            <Typography>Начальное значение</Typography>
            <CustomTextField
              placeholder={"50"}
              text={String(listQuestions[totalIndex].content.start)}
              onChange={({ target }) => {
                const clonContent = listQuestions[totalIndex].content;
                clonContent.start = Number(target.value);
                updateQuestionsList(totalIndex, { content: clonContent });
              }}
            />
          </Box>
          <Box>
            <Typography>Шаг</Typography>
            <CustomTextField
              placeholder={"1"}
              text={String(listQuestions[totalIndex].content.step)}
              onChange={({ target }) => {
                const clonContent = listQuestions[totalIndex].content;
                clonContent.step = Number(target.value);
                updateQuestionsList(totalIndex, { content: clonContent });
              }}
            />
          </Box>
        </Box>
      </Box>
      <ButtonsOptions
        switchState={switchState}
        SSHC={SSHC}
        totalIndex={totalIndex}
      />
      <SwitchSlider switchState={switchState} totalIndex={totalIndex} />
    </>
  );
}
