import Title from "@/components/Title";
import styles from "./styles.module.css";
import MainButton from "@/components/MainButton";
import { useNavigate, useSearchParams } from "react-router-dom";
import routes from "@/routes";
import { useTranslations } from "@/hooks/translations";
import { ELocalesPlacement } from "@/locales";
import { useSelector } from "react-redux";
import { selectors } from "@/store";

function GetInformationPartnerPage() {
  const { translate } = useTranslations(ELocalesPlacement.V1);
  const navigate = useNavigate();
  const [searchParams] = useSearchParams();
  const path = searchParams.get("path");
  const token = useSelector(selectors.selectToken);

  const handleBack = () => {
    if (path === "back") {
      return navigate(-1);
    }
    if (path === "palmistry-v1") {
      return navigate(routes.client.palmistryV1SkipTrial());
      // return navigate(routes.client.addGuides());
    }
    if (path === "palmistry") {
      return navigate(routes.client.skipTrial());
      // return navigate(routes.client.addGuides());
    }
    if (path === "compatibility") {
      return navigate(routes.client.compatibilityV2SkipTrial());
    }
    if (path === "email-compatibility") {
      return navigate(routes.client.emailMarketingV1SkipTrial());
    }
    if (path === "email-palmistry") {
      return navigate(routes.client.palmistryV2SkipTrial());
    }
    navigate(routes.client.addConsultationV1());
  };

  const handleNext = () => {
    // if (path === "palmistry" || path === "palmistry-v1") {
    //   // return navigate(
    //   //   `${routes.client.palmistryOnboardingV1()}?path=palmistry`
    //   // );
    //   return navigate(routes.client.home());
    // }
    // if (path === "compatibility") {
    //   // return navigate(`${routes.client.palmistryOnboardingV1()}?path=compatibility`);
    //   return navigate(routes.client.home());
    // }
    // if (path === "email-compatibility") {
    //   // return navigate(routes.client.emailMarketingV1Onboarding());
    //   return navigate(routes.client.home());
    // }
    // if (path === "email-palmistry") {
    //   // return navigate(routes.client.palmistryV2Onboarding());
    //   return navigate(routes.client.home());
    // }
    // navigate(routes.client.home());
    return window.location.replace(`https://app.witlab.us/auth/callback?jwtToken=${token}&nextUrl=/`);
  };

  return (
    <section className={`${styles.page} page`}>
      <video
        className={styles["background-video"]}
        loop={false}
        autoPlay={true}
        muted={true}
        playsInline={true}
      >
        <source src="/videos/background-video-1.mp4" type="video/mp4" />
        <source src="/videos/background-video-1.mp4" type="video/ogg" />
        Your browser does not support the video tag.
      </video>
      <Title variant="h2" className={styles.title}>
        {translate("app_name")}
      </Title>
      <div className={styles["bottom-container"]}>
        <Title variant="h3" className={styles.subtitle}>
          {translate("/get-information-partner.title")}
        </Title>
        <p className={styles.description}>
          {translate("/get-information-partner.description")}
        </p>
        <div className={styles["buttons-container"]}>
          <MainButton
            onClick={handleBack}
            className={`${styles.button} ${styles["back-button"]}`}
          >
            {translate("back")}
          </MainButton>
          <MainButton
            onClick={handleNext}
            className={`${styles.button} ${styles["next-button"]}`}
          >
            {translate("next")}
          </MainButton>
        </div>
      </div>
    </section>
  );
}

export default GetInformationPartnerPage;
