import Title from "@/components/Title";
import styles from "./styles.module.css";
import MainButton from "@/components/MainButton";
import { useNavigate } from "react-router-dom";
import routes from "@/routes";
import { useSelector } from "react-redux";
import { selectors } from "@/store";
import { getZodiacSignByDate } from "@/services/zodiac-sign";
import { useDynamicSize } from "@/hooks/useDynamicSize";
import Header from "../../components/Header";
import BackgroundTopBlob from "../../ui/BackgroundTopBlob";
import { DotLottieReact } from "@lottiefiles/dotlottie-react";
import { ELottieKeys, useLottie } from "@/hooks/lottie/useLottie";
import { useMetricABFlags } from "@/services/metric/metricService.ts";
import { useTranslations } from "@/hooks/translations";
import { ELocalesPlacement } from "@/locales";

function BothPage() {
  const navigate = useNavigate();
  const { translate } = useTranslations(ELocalesPlacement.V1);
  const birthdate = useSelector(selectors.selectBirthdate);
  const zodiacSign = getZodiacSignByDate(birthdate);
  const { width: pageWidth, elementRef: pageRef } = useDynamicSize({});
  const { flags } = useMetricABFlags();
  const aboutUsAnswersKey = flags?.aboutUsAnswers?.[0];
  const { animationData } = useLottie({
    loadKey: ELottieKeys.scalesNeutral,
  });

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

  const handleNext = () => {
    navigate(routes.client.aboutUsV1(aboutUsAnswersKey));
  };

  return (
    <section className={`${styles.page} page`} ref={pageRef}>
      <BackgroundTopBlob
        width={pageWidth}
        height={387}
        className={styles["background-top-blob"]}
      />
      <Header isBackButtonVisible={false} />
      <div className={styles["image-container"]}>
        {animationData && (
          <DotLottieReact
            className={`${styles["lottie-animation"]} ym-hide-content`}
            data={animationData}
            autoplay
            loop={false}
          />
        )}
      </div>
      <div>
        <Title variant="h1" className={styles.title}>
          {translate("/both.title", {
            wonderful: (
              <span style={{ color: "#A6FD18" }}>{translate("/both.wonderful")}</span>
            ),
            zodiacSign: (
              <span style={{ color: "#A6FD18" }}>
                {translate(`zodiac_signs.${zodiacSign?.toLowerCase()}`)}
              </span>
            ),
          })}
        </Title>
      </div>
      <div className={styles["buttons-container"]}>
        <MainButton
          className={`${styles.button} ${styles["back-button"]}`}
          onClick={handleBack}
        >
          {translate("back")}
        </MainButton>
        <MainButton
          className={`${styles.button} ${styles["next-button"]}`}
          onClick={handleNext}
        >
          {translate("next")}
        </MainButton>
      </div>
    </section>
  );
}

export default BothPage;
