import styles from "./styles.module.scss";
import Title from "@/components/Title";
import { useTranslations } from "@/hooks/translations";
import { ELocalesPlacement } from "@/locales";
import { getZodiacSignByDate } from "@/services/zodiac-sign";
import { useSelector } from "react-redux";
import { selectors } from "@/store";
import Button from "../../components/Button";
import { useNavigate } from "react-router-dom";
import routes from "@/routes";
import { useMemo } from "react";

function HeadOrHeartResult() {
  const navigate = useNavigate();
  const { translate } = useTranslations(ELocalesPlacement.CompatibilityV4);
  const { headOrHeart, relationshipStatus } = useSelector(selectors.selectCompatibilityV4Answers);
  const { gender, partnerGender, partnerBirthdate } = useSelector(selectors.selectQuestionnaire);
  const translatePrefix = relationshipStatus === "single" ? "single" : "with-partner";

  // const { isReady, variant } = useUnleash({
  //   flag: EUnleashFlags.headOrHeartResultPageCompatibilityV4,
  // });

  const birthdate = useSelector(selectors.selectBirthdate);
  const zodiacSign = getZodiacSignByDate(birthdate);
  const zodiacSignPartner = getZodiacSignByDate(partnerBirthdate);

  const handleBack = () => {
    navigate(-1);
  };

  const handleNext = () => {
    // navigate(`${routes.client.compatibilityV4RelateFollowing()}/1`);
    navigate(routes.client.compatibilityV4AlmostThere());
  };

  const imageUrl = useMemo(() => {
    const imageName = headOrHeart === "depends" ? "both" : headOrHeart;
    return `/v4/compatibility/head-or-heart-result/${imageName}.svg`;
  }, [headOrHeart]);

  // if (!isReady) return <Loader color={LoaderColor.Black} />;

  return (
    <section className={styles.container}>
      <img
        src={imageUrl}
        alt="result image"
        className={styles.image}
      />
      <Title variant="h1" className={styles.title}>
        {headOrHeart === "both" &&
          translate(`/both.${translatePrefix}.title`, {
            wonderful: (
              <b>
                {translate(`/both.${translatePrefix}.wonderful`)}
              </b>
            ),
            zodiacSign: (
              <b>
                {translate(`zodiac_signs.${zodiacSign?.toLowerCase()}`)}
              </b>
            ),
            partnerZodiacSign: (
              <b>
                {translate(`zodiac_signs.${zodiacSignPartner?.toLowerCase()}`)}
              </b>
            ),
            gender: translate(gender?.toLowerCase()).toLowerCase(),
            partnerGender: translate(partnerGender?.toLowerCase()).toLowerCase(),
            percent: (
              <b>
                15%
              </b>
            )
          })}
        {headOrHeart === "head" &&
          translate(`/with-head.${translatePrefix}.title`, {
            zodiacSign: (
              <b>
                {translate(`zodiac_signs.${zodiacSign?.toLowerCase()}`)}
              </b>
            ),
            partnerZodiacSign: (
              <b>
                {translate(`zodiac_signs.${zodiacSignPartner?.toLowerCase()}`)}
              </b>
            ),
            gender: translate(gender?.toLowerCase()).toLowerCase(),
            partnerGender: translate(partnerGender?.toLowerCase()).toLowerCase(),
            percent: (
              <b>
                35%
              </b>
            )
          })}
        {headOrHeart === "heart" &&
          translate(`/with-heart.${translatePrefix}.title`, {
            zodiacSign: (
              <b>
                {translate(`zodiac_signs.${zodiacSign?.toLowerCase()}`)}
              </b>
            ),
            partnerZodiacSign: (
              <b>
                {translate(`zodiac_signs.${zodiacSignPartner?.toLowerCase()}`)}
              </b>
            ),
            gender: translate(gender?.toLowerCase()).toLowerCase(),
            partnerGender: translate(partnerGender?.toLowerCase()).toLowerCase(),
            percent: (
              <b>
                51%
              </b>
            )
          })}
        {headOrHeart === "depends" &&
          translate(`/depends.${translatePrefix}.title`, {
            zodiacSign: (
              <b>
                {translate(`zodiac_signs.${zodiacSign?.toLowerCase()}`)}
              </b>
            ),
            partnerZodiacSign: (
              <b>
                {translate(`zodiac_signs.${zodiacSignPartner?.toLowerCase()}`)}
              </b>
            ),
            gender: translate(gender?.toLowerCase()).toLowerCase(),
            partnerGender: translate(partnerGender?.toLowerCase()).toLowerCase(),
            percent: (
              <b>
                9%
              </b>
            )
          })
        }
      </Title>
      <div className={styles["buttons-container"]}>
        <Button
          className={`${styles.button} ${styles["back-button"]}`}
          onClick={handleBack}
        >
          {translate("back")}
        </Button>
        <Button
          className={`${styles.button} ${styles["next-button"]}`}
          onClick={handleNext}
        >
          {translate("next")}
        </Button>
      </div>
    </section>
  );
}

export default HeadOrHeartResult;
