import { useState } from "react";
import { Box, Typography, Link, useTheme, useMediaQuery } from "@mui/material";
import { AnswerDraggableList } from "../AnswerDraggableList";
import { EnterIcon } from "../../../assets/icons/questionsPage/enterIcon";
import SwitchDropDown from "./switchDropDown";
import ButtonsOptions from "../ButtonsOptions";
import { addQuestionVariant } from "@root/questions/actions";
import { useAddAnswer } from "../../../utils/hooks/useAddAnswer";

import type { QuizQuestionSelect } from "../../../model/questionTypes/select";
interface Props {
  question: QuizQuestionSelect;
}

export default function DropDown({ question }: Props) {
  const onClickAddAnAnswer = useAddAnswer();
  const [switchState, setSwitchState] = useState("setting");
  const theme = useTheme();
  const isMobile = useMediaQuery(theme.breakpoints.down(790));

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

  return (
    <>
      <Box
        sx={{
          padding: isMobile ? "15px 20px 20px 20px" : "20px 20px 20px 20px ",
        }}
      >
        {question.content.variants.length === 0 ? (
          <Typography
            sx={{
              padding: "0 0 33px 80px",
              fontWeight: 400,
              fontSize: "18px",
              lineHeight: "21.33px",
              color: theme.palette.grey2.main,
            }}
          >
            Добавьте ответ
          </Typography>
        ) : (
          <AnswerDraggableList question={question} />
        )}
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
            marginBottom: "20px",
          }}
        >
          <Link
            component="button"
            variant="body2"
            sx={{
              color: theme.palette.brightPurple.main,
              fontWeight: "400",
              fontSize: "16px",
              mr: "4px",
              height: "19px",
            }}
            onClick={() => onClickAddAnAnswer(question)}
          >
            Добавьте ответ
          </Link>
          {isMobile ? null : (
            <>
              <Typography
                sx={{
                  fontWeight: 400,
                  lineHeight: "21.33px",
                  color: theme.palette.grey2.main,
                  fontSize: "16px",
                }}
              >
                или нажмите Enter
              </Typography>
              <EnterIcon
                style={{
                  color: "#7E2AEA",
                  fontSize: "24px",
                  marginLeft: "6px",
                }}
              />
            </>
          )}
        </Box>
      </Box>
      <ButtonsOptions switchState={switchState} SSHC={SSHC} question={question} />
      <SwitchDropDown switchState={switchState} question={question} />
    </>
  );
}
