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 { useDynamicSize } from "@/hooks/useDynamicSize";
import BackgroundTopBlob from "../../ui/BackgroundTopBlob";
import Header from "../../components/Header";
import { DotLottieReact } from "@lottiefiles/dotlottie-react";
import { ELottieKeys, useLottie } from "@/hooks/lottie/useLottie";
import { usePreloadImages } from "@/hooks/preload/images";
import { useTranslations } from "@/hooks/translations";
import { ELocalesPlacement } from "@/locales";

function GoalSetupPage() {
  const navigate = useNavigate();
  const { width: pageWidth, elementRef } = useDynamicSize({});
  const { translate } = useTranslations(ELocalesPlacement.V1);
  usePreloadImages([
    "/check_mark_button.webp",
    "/cross_mark.webp",
    "/man_student.webp",
    "/face_with_monocle.webp",
    "/slightly_smiling_face.webp",
  ]);

  const { animationData } = useLottie({
    loadKey: ELottieKeys.goal,
  });

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

  const handleNext = () => {
    navigate(`${routes.client.questionnaireV1()}/profile/parent`);
  };

  return (
    <section className={`${styles.page} page`} ref={elementRef}>
      <BackgroundTopBlob
        className={styles["background-top-blob"]}
        width={pageWidth}
        height={400}
      />
      <Header isBackButtonVisible={false} />
      <div className={styles["image-container"]}>
        {animationData && (
          <DotLottieReact
            className={`${styles["lottie-animation"]} ym-hide-content`}
            data={animationData}
            autoplay
            loop={false}
          />
        )}
      </div>
      <div className={styles["text-container"]}>
        <Title variant="h1" className={styles.title}>
          {translate("/goal-setup.title")}
        </Title>
        <p className={styles.text}>{translate("/goal-setup.description")}</p>
      </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>
      <div className={styles.circle} />
    </section>
  );
}

export default GoalSetupPage;
