import styles from "./styles.module.css";
import { useSchemeColorByElement } from "@/hooks/useSchemeColorByElement";
import { useRef } from "react";
import { Outlet, useLocation } from "react-router-dom";
import routes from "@/routes";
import Header from "@/components/PalmistryV1/components/Header";

const isBackButtonVisibleRoutes = [
  routes.client.palmistryV1Birthdate(),
  routes.client.palmistryV1PalmsInformation(),
  routes.client.palmistryV1WhatAspects(),
  routes.client.palmistryV1RelationshipStatus(),
  routes.client.palmistryV1ElementResonates(),
  routes.client.palmistryV1FavoriteColor(),
  routes.client.palmistryV1HeadOrHeart(),
  routes.client.palmistryV1RelateFollowing(),
  routes.client.palmistryV1LetScan(),
  routes.client.palmistryV1ScanInstruction(),
  routes.client.palmistryV1ScannedPhoto(),
  routes.client.palmistryV1Email(),
  routes.client.palmistryV1TrialChoice(),
  routes.client.palmistryV1TrialPayment(),
  routes.client.palmistryV1Payment(),
];

function LayoutPalmistryV1() {
  const location = useLocation();
  const mainRef = useRef<HTMLDivElement>(null);
  useSchemeColorByElement(mainRef.current, "section.page, .page, section", [
    location,
  ]);

  const getIsBackButtonVisible = () => {
    for (const route of isBackButtonVisibleRoutes) {
      if (location.pathname.includes(route)) return true;
    }
    return false;
  };

  return (
    <>
      <main className={`${styles.main} content`} ref={mainRef}>
        <Header
          className={styles.header}
          classNameTitle={styles["header-title"]}
          isBackButtonVisible={getIsBackButtonVisible()}
        />
        {/* <Suspense fallback={<LoadingPage />}> */}
        <section className={styles.page}>
          <Outlet />
        </section>
        {/* </Suspense> */}
      </main>
    </>
  );
}

export default LayoutPalmistryV1;
