import { useState } from "react";
import { Box, IconButton, TextField, Typography } from "@mui/material";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import DeleteIcon from "@icons/questionsPage/deleteIcon";
import CustomButton from "../CustomButton";

import PriceButtons from "./PriceButton";
import DiscountButtons from "./DiscountButtons";
import ButtonsOptions from "../../pages/Questions/ButtonsOptions";

import CustomTextField from "@ui_kit/CustomTextField";

import OneIcon from "@icons/questionsPage/OneIcon";
import PointsIcon from "@icons/questionsPage/PointsIcon";
import ImageAndVideoButtons from "./ImageAndVideoButtons";
import Info from "@icons/Info";
import SwitchAnswerOptions from "./SwitchAnswerOptions";
import ButtonsOptionsForm from "./ButtinsOptionsForm";

export default function DescriptionForm() {
  const [switchState, setSwitchState] = useState("setting");
  const [callToAction, setCallToAction] = useState<boolean>(false);
  const [priceButtonsActive, setPriceButtonsActive] = useState<number>(0);
  const [priceButtonsType, setPriceButtonsType] = useState<string>();
  const [forwarding, setForwarding] = useState<boolean>(false);

  const ButtonsActive = (index: number, type: string) => {
    setPriceButtonsActive(index);
    setPriceButtonsType(type);
  };

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

  return (
    <Box
      sx={{
        width: "796px",
        height: "100%",
        bgcolor: "#FFFFFF",
        borderRadius: "12px",
      }}
    >
      <Box sx={{ p: "0 20px", pt: "30px" }}>
        <Box sx={{ width: "100%", maxWidth: "760px", display: "flex", alignItems: "center", gap: "10px", mb: "19px" }}>
          <CustomTextField placeholder="Заголовок вопроса" text={""} />
          <IconButton>
            <ExpandMoreIcon />
          </IconButton>
          <OneIcon />
          <PointsIcon />
        </Box>

        <Box sx={{ display: "flex" }}>
          <PriceButtons ButtonsActive={ButtonsActive} priceButtonsActive={priceButtonsActive} />
          <DiscountButtons />
        </Box>

        <TextField
          // value={text}

          fullWidth
          placeholder="Описание"
          sx={{
            "& .MuiInputBase-root": {
              backgroundColor: "#F2F3F7",
              width: "100%",
              height: "110px",
              borderRadius: "10px",
            },
          }}
          inputProps={{
            sx: {
              borderRadius: "10px",
              fontSize: "18px",
              lineHeight: "21px",
              py: 0,
            },
          }}
        />
        <ImageAndVideoButtons />
        {priceButtonsType === "smooth" ? (
          <Box sx={{ mb: "20px" }}>
            <Box sx={{ display: "flex", alignItems: "center", mb: "14xp" }}>
              <Typography component={"h6"} sx={{ weight: "500", fontSize: "18px" }}>
                Призыв к действию
              </Typography>
              <IconButton sx={{ borderRadius: "6px", padding: "2px" }}>
                <DeleteIcon />
              </IconButton>
            </Box>
            <Box sx={{ display: "flex" }}>
              <TextField
                // value={text}
                placeholder="Узнать подробнее"
                fullWidth
                sx={{
                  width: "410px",
                  "& .MuiInputBase-root": {
                    backgroundColor: "#F2F3F7",
                    width: "410px",
                    height: "48px",
                    borderRadius: "10px",
                  },
                }}
                inputProps={{
                  sx: {
                    borderRadius: "10px",
                    fontSize: "18px",
                    lineHeight: "21px",
                    py: 0,
                  },
                }}
              />
              <CustomButton
                onClick={() => setForwarding(true)}
                variant="contained"
                sx={{
                  display: forwarding ? "none" : "",
                  ml: "20px",
                  mb: "20px",
                  color: "#9A9AAF",
                  backgroundColor: "#F2F3F7",
                  width: "194px",
                  height: "48px",
                  border: "1px solid #9A9AAF",
                }}
              >
                Переадрисация +
              </CustomButton>
              {forwarding ? (
                <Box sx={{ ml: "20px", mt: "-36px" }}>
                  <Box sx={{ display: "flex", alignItems: "center", mb: "14xp" }}>
                    <Typography component={"h6"} sx={{ weight: "500", fontSize: "18px" }}>
                      Переадресация
                    </Typography>
                    <IconButton sx={{ borderRadius: "6px", padding: "2px" }}>
                      <DeleteIcon />
                    </IconButton>
                    <Info />
                  </Box>
                  <Box>
                    <TextField
                      // value={text}
                      placeholder="https://exemple.ru"
                      fullWidth
                      sx={{
                        "& .MuiInputBase-root": {
                          backgroundColor: "#F2F3F7",
                          width: "326px",
                          height: "48px",
                          borderRadius: "10px",
                        },
                      }}
                      inputProps={{
                        sx: {
                          borderRadius: "10px",
                          fontSize: "18px",
                          lineHeight: "21px",
                          py: 0,
                        },
                      }}
                    />
                  </Box>
                </Box>
              ) : (
                ""
              )}
            </Box>
          </Box>
        ) : (
          <CustomButton
            onClick={() => setCallToAction(true)}
            variant="contained"
            sx={{
              mb: "20px",
              color: "#9A9AAF",
              backgroundColor: "#F2F3F7",
              width: "119px",
              height: "48px",
              border: "1px solid #9A9AAF",
            }}
          >
            Кнопка +
          </CustomButton>
        )}
      </Box>
      <ButtonsOptionsForm switchState={switchState} SSHC={SSHC} />
      <SwitchAnswerOptions switchState={switchState} />
    </Box>
  );
}
