import { useSchemeColorByElement } from "@/hooks/useSchemeColorByElement";
import { useRef } from "react";
import { Outlet, useLocation } from "react-router-dom";
import routes from "@/routes";
import StepperBar from "@/components/CompatibilityV2/components/StepperBar";
import styles from "./styles.module.scss";
import { useSelector } from "react-redux";
import { selectors } from "@/store";

const stepperRoutes = [
  routes.client.compatibilityV2Birthdate(),
  routes.client.compatibilityV2PalmsInformation(),
  // routes.client.compatibilityV2WhatAspects(),
  routes.client.compatibilityV2RelationshipStatus(),
  routes.client.compatibilityV2RelateFollowing(),
  routes.client.compatibilityV2RomanticGestures(),
  routes.client.compatibilityV2CheckingPhone(),
  routes.client.compatibilityV2BirthdatePartner(),
  routes.client.compatibilityV2PalmsInformationPartner(),
  routes.client.compatibilityV2DateEvent(),

  // routes.client.compatibilityV2ElementResonates(),
  // routes.client.compatibilityV2FavoriteColor(),
  routes.client.compatibilityV2HeadOrHeart(),
  routes.client.compatibilityV2HeadOrHeartResult(),
  routes.client.compatibilityV2Email(),
];

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

  const getCurrentStep = () => {
    let index = 0;
    for (const route of stepperRoutes) {
      if (location.pathname.includes(route)) {
        if (location.pathname.includes(routes.client.compatibilityV2BirthdatePartner())) {
          return 8;
        }
        if (location.pathname.includes(routes.client.compatibilityV2PalmsInformationPartner())) {
          return 9;
        }
        return index + 1;
      }


      index++;

    }
    return 0;
  };

  return (
    <>
      <StepperBar
        length={stepperRoutes.length}
        currentStep={getCurrentStep()}
        color={darkTheme ? "#B2BCFF" : "#353E75"}
        className={styles["stepper-bar"]}
      />
      <Outlet />
    </>
  );
}

export default StepperLayout;
