import routes, { palmistryV1Prefix } from "@/routes";
import { Route, Routes } from "react-router-dom";
import LayoutPalmistryV1 from "./LayoutPalmistryV1";
import FindHappiness from "@/components/PalmistryV1/pages/FindHappiness";
import StepperLayoutPalmistryV1 from "./StepperLayoutPalmistryV1";
import Birthdate from "@/components/PalmistryV1/pages/Birthdate";
import PalmsInformation from "@/components/PalmistryV1/pages/PalmsInformation";
import NotFoundPage from "@/components/NotFoundPage";
import WhatAspects from "@/components/PalmistryV1/pages/WhatAspects";
import RelationshipStatus from "@/components/PalmistryV1/pages/RelationshipStatus";
import ElementResonates from "@/components/PalmistryV1/pages/ElementResonates";
import FavoriteColor from "@/components/PalmistryV1/pages/FavoriteColor";
import HeadOrHeart from "@/components/PalmistryV1/pages/HeadOrHeart";
import HeadOrHeartResult from "@/components/PalmistryV1/pages/HeadOrHeartResult";
import RelateFollowing from "@/components/PalmistryV1/pages/RelateFollowing";
import LetScan from "@/components/PalmistryV1/pages/LetScan";
import ScanInstruction from "@/components/PalmistryV1/pages/ScanInstruction";
import Camera from "@/components/PalmistryV1/pages/Camera";
import ScannedPhoto from "@/components/PalmistryV1/pages/ScannedPhoto";
import Email from "@/components/PalmistryV1/pages/Email";
import TrialChoice from "@/components/PalmistryV1/pages/TrialChoice";
import TrialPayment from "@/components/PalmistryV1/pages/TrialPayment";
import Payment from "@/components/PalmistryV1/pages/Payment";
import { useEffect } from "react";
import { useDispatch } from "react-redux";
import { actions } from "@/store";
import GenderPalmistry from "@/components/PalmistryV1/pages/GenderPalmistry";
import CheckSubscriptionOutlet from "./CheckSubscriptionOutlet";
import TrialChoiceVideo from "@/components/PalmistryV1/pages/TrialChoiceVideo";
import LayoutPersonalVideo from "./LayoutPersonalVideo";
import OnboardingPage from "@/components/pages/ABDesign/v1/pages/Onboarding";
import SaveOff from "@/components/PalmistryV1/pages/SaveOff";
import SecretDiscount from "@/components/PalmistryV1/pages/SecretDiscount";

const removePrefix = (path: string) => path.replace(palmistryV1Prefix, "");

function PalmistryV1Routes() {
  const dispatch = useDispatch();

  useEffect(() => {
    dispatch(actions.palmistry.update({ fromRedesign: true }));
  }, [dispatch]);

  return (
    <Routes>
      <Route
        path={removePrefix(routes.client.palmistryOnboardingV1())}
        element={<OnboardingPage />}
      />
      <Route
        path={removePrefix(routes.client.palmistryV1SecretDiscount())}
        element={<SecretDiscount />}
      />
      <Route element={<LayoutPalmistryV1 />}>
        <Route
          element={
            <CheckSubscriptionOutlet
              subscribedReturnUrl={routes.client.skipTrial()}
            />
          }
        >
          <Route element={<LayoutPersonalVideo />}>
            <Route
              path={removePrefix(routes.client.palmistryV1Gender())}
              element={<GenderPalmistry />}
            />
            <Route
              path={removePrefix(routes.client.palmistryV1Welcome())}
              element={<FindHappiness />}
            >
              <Route path="*" element={<FindHappiness />} />
            </Route>
            <Route element={<StepperLayoutPalmistryV1 />}>
              <Route
                path={removePrefix(routes.client.palmistryV1Birthdate())}
                element={<Birthdate />}
              />
              <Route
                path={removePrefix(routes.client.palmistryV1PalmsInformation())}
                element={<PalmsInformation />}
              />
              <Route
                path={removePrefix(routes.client.palmistryV1WhatAspects())}
                element={<WhatAspects />}
              />
              <Route
                path={removePrefix(
                  routes.client.palmistryV1RelationshipStatus()
                )}
                element={<RelationshipStatus />}
              />
              <Route
                path={removePrefix(routes.client.palmistryV1ElementResonates())}
                element={<ElementResonates />}
              />
              <Route
                path={removePrefix(routes.client.palmistryV1FavoriteColor())}
                element={<FavoriteColor />}
              />
              <Route
                path={removePrefix(routes.client.palmistryV1HeadOrHeart())}
                element={<HeadOrHeart />}
              />
              <Route
                path={removePrefix(
                  routes.client.palmistryV1HeadOrHeartResult()
                )}
                element={<HeadOrHeartResult />}
              />
              <Route
                path={removePrefix(routes.client.palmistryV1RelateFollowing())}
                element={<RelateFollowing />}
              >
                <Route path=":questionId" element={<RelateFollowing />} />
              </Route>
              <Route
                path={removePrefix(routes.client.palmistryV1Email())}
                element={<Email />}
              />
            </Route>
            <Route
              path={removePrefix(routes.client.palmistryV1LetScan())}
              element={<LetScan />}
            />
            <Route
              path={removePrefix(routes.client.palmistryV1ScanInstruction())}
              element={<ScanInstruction />}
            />
            <Route
              path={removePrefix(routes.client.palmistryV1Camera())}
              element={<Camera />}
            />
            <Route
              path={removePrefix(routes.client.palmistryV1TrialChoice())}
              element={<TrialChoice />}
            />

            <Route
              path={removePrefix(routes.client.palmistryV1TrialChoiceVideo())}
              element={<TrialChoiceVideo />}
            />

            <Route
              path={removePrefix(routes.client.palmistryV1TrialPayment())}
              element={<TrialPayment />}
            />
            <Route
              path={removePrefix(routes.client.palmistryV1Payment())}
              element={<Payment />}
            />
          </Route>
          <Route
            path={removePrefix(routes.client.palmistryV1ScannedPhoto())}
            element={<ScannedPhoto />}
          />
          <Route
            path={removePrefix(routes.client.palmistryV1SaveOff())}
            element={<SaveOff />}
          />
          <Route path="*" element={<NotFoundPage />} />
        </Route>
      </Route>
    </Routes>
  );
}

export default PalmistryV1Routes;
