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/CompatibilityV3/components/Header";

const isBackButtonVisibleRoutes = [
  routes.client.compatibilityV3Birthdate(),
  routes.client.compatibilityV3PalmsInformation(),
  routes.client.compatibilityV3WhatAspects(),
  routes.client.compatibilityV3RelationshipStatus(),
  routes.client.compatibilityV3ElementResonates(),
  routes.client.compatibilityV3FavoriteColor(),
  routes.client.compatibilityV3HeadOrHeart(),
  routes.client.compatibilityV3RelateFollowing(),
  routes.client.compatibilityV3LetScan(),
  routes.client.compatibilityV3ScanInstruction(),
  routes.client.compatibilityV3ScannedPhoto(),
  routes.client.compatibilityV3Email(),
  routes.client.compatibilityV3TrialChoice(),
  routes.client.compatibilityV3TrialPayment(),
  routes.client.compatibilityV3TryApp(),
  routes.client.compatibilityV3Payment(),
];

function Layout() {
  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 Layout;
