import { Box, Button, IconButton, SxProps, Theme, Typography } from "@mui/material";

import Info from "@icons/Info";
import CustomButton from "./CustomButton";
import SwichResult from "./SwichResult";

import listChecks from "../assets/icon/listChecks.svg";
import ShareNetwork from "../assets/icon/ShareNetwork.svg";
import ArrowCounterClockWise from "../assets/icon/ArrowCounterClockWise.svg";
import { useState } from "react";

const buttonSetting: { title: string; sx: SxProps<Theme>; type: string }[] = [
  {
    sx: { backgroundColor: "#7E2AEA", color: "white", width: "237px", height: "44px" },
    title: "До формы контактов",
    type: "toContactForm",
  },
  {
    sx: { backgroundColor: "#F2F3F7", color: "#9A9AAF", width: "266px", height: "44px", border: "1px solid #9A9AAF" },
    title: "После формы контактов",
    type: "afterСontactForm",
  },
  {
    sx: { color: "#9A9AAF", backgroundColor: "#F2F3F7", width: "233px", height: "44px", border: "1px solid #9A9AAF" },
    title: "Отправить на E-mail",
    type: "e-mail",
  },
];

export default function SettingForm() {
  const [activeIndex, setActiveIndex] = useState<number>();
  const [typeActive, setTypeActive] = useState<string>();

  const active = (index: number, type: string) => {
    setActiveIndex(index);
    setTypeActive(type);
  };

  return (
    <Box sx={{ width: "796px" }}>
      <Box sx={{ display: "flex", alignItems: "center", mb: "40px" }}>
        <Typography sx={{ pr: "10px" }} variant="h5">
          Настройки результатов
        </Typography>
        <Info />
      </Box>
      <Box
        sx={{
          height: "100%",
          bgcolor: "#FFFFFF",
          borderRadius: "12px",
          p: "30px 20px",
        }}
      >
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
            justifyContent: "space-between",
            mb: "20px",
          }}
        >
          <Typography sx={{ color: "#9A9AAF" }}>Показывать результат</Typography>
          <IconButton>
            <svg width="30" height="30" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">
              <rect width="30" height="30" rx="6" fill="#EEE4FC" />
              <path
                d="M22.5 11.25L15 18.75L7.5 11.25"
                stroke="#7E2AEA"
                stroke-width="1.5"
                stroke-linecap="round"
                stroke-linejoin="round"
              />
            </svg>
          </IconButton>
        </Box>
        <Box sx={{ display: "flex", justifyContent: "space-between", mb: "20px" }}>
          {buttonSetting.map(({ sx, title, type }, index) => (
            <CustomButton
              disableRipple
              onClick={() => active(index, type)}
              key={title}
              sx={{
                ...sx,
                bgcolor: activeIndex === index ? " #7E2AEA" : "#F2F3F7",
                color: activeIndex === index ? " white" : "#9A9AAF",
              }}
            >
              {title}
            </CustomButton>
          ))}
        </Box>
        {typeActive === "e-mail" ? (
          <SwichResult icon={listChecks} text="Показывать несколько результатов" />
        ) : (
          <>
            <SwichResult icon={listChecks} text="Показывать несколько результатов" />
            <SwichResult icon={ShareNetwork} text="Поделиться результатами" />
            <SwichResult icon={ArrowCounterClockWise} text="Кнопка `Пройти тест заново`" />
          </>
        )}
      </Box>
      <Box sx={{ display: "flex", alignItems: "center", mb: "15px", mt: "15px" }}>
        <Typography variant="p1" sx={{ color: "#4D4D4D", fontSize: "14px" }}>
          Создайте результат
        </Typography>
        <Button
          disableRipple
          sx={{
            ml: "auto",
            height: "19px",
            color: "#7E2AEA",
            textDecoration: "underline",
            fontSize: "16px",

            "&:hover": {
              background: "none",
              textDecoration: "underline",
            },
          }}
          variant="text"
        >
          Свернуть всё
        </Button>
      </Box>
    </Box>
  );
}
