import { createBrowserRouter, Navigate } from "react-router-dom";
import { lazy, Suspense } from "react";
import TermloansLoaderScreen from "@/components/TermloansLoaderScreen";
import ProtectedRoute from "@/components/ProtectedRoute";
import AnimatedPage from "@/Layout/AnimatedPage";
import AuthOnlyRoute from "@/components/AuthOnlyRoute";
// Lazy loaded components - grouped by feature for better chunking
// Authentication pages
const Login = lazy(() => import("@/pages/NewPages/Login"));
const VerificationCode = lazy(() => import("@/pages/NewPages/VerificationCode"));
const ForgotPassword = lazy(() => import("@/pages/NewPages/ForgotPassword"));
const RecoverPassword = lazy(() => import("@/pages/NewPages/RecoverPassword"));
const EmailVerificationAccount = lazy(() => import("@/pages/NewPages/EmailVerificationAccount"));
const GoogleCallbackPage = lazy(() => import("@/pages/NewPages/GoogleCallback"));
// Registration and onboarding pages
const CreateAccountPage = lazy(() => import("@/pages/NewPages/Forms/CreateAccount"));
const ApplyAccountPage = lazy(() => import("@/pages/NewPages/Forms/ApplyAccount"));
// const QuizAccountPage = lazy(() => import("@/pages/NewPages/Forms/QuizAccount"));
const NexusAccountPage = lazy(() => import("@/pages/NewPages/Forms/NexusAccount"));
const RegistrationPage = lazy(() => import("@/pages/NewPages/Forms/Typeform"));
const ApplyTypeFormPage = lazy(() => import("@/pages/NewPages/Forms/ApplyTypeform"));
// const QuizTypeFormPage = lazy(() => import("@/pages/NewPages/Forms/QuizTypeform"));
const NexusTypeFormPage = lazy(() => import("@/pages/NewPages/Forms/NexusTypeform"));
const MagicLinkTypeform = lazy(() => import("@/pages/NewPages/Forms/MagicLinkTypeform"));
// Banking integration pages
const PlaidPage = lazy(() => import("@/pages/NewPages/Plaid"));
const PlaidProcessingPage = lazy(() => import("@/pages/NewPages/PlaidProcessing"));
// Core application pages
const RequestInProgressPage = lazy(() => import("@/pages/NewPages/RequestInProgress"));
// Error and utility pages
const NotFoundPage = lazy(() => import("@/pages/NewPages/NotFound"));
const ErrorBoundaryPage = lazy(() => import("@/pages/NewPages/ErrorBoundary"));
// Legal pages
const PrivacyPolicy = lazy(() => import("@/pages/Legal/PrivacyPolicy"));
const TermsOfService = lazy(() => import("@/pages/Legal/TermsOfService"));
// Wrapper component for lazy loaded pages with Suspense
const LazyPage = ({ children }: { children: React.ReactNode }) => (
}>
{children}
);
const publicRoutes = [
{
path: "",
element: ,
},
{
path: "/home",
element: ,
},
{
path: "/login",
element: ,
},
{
path: "/recover-password",
element: ,
},
{
path: "/register",
element: ,
},
{
path: "/apply",
element: ,
},
// {
// path: "/quiz",
// element: ,
// },
{
path: "/quiz",
element: ,
},
{
path: "/reset-password/verify",
element: ,
},
{
path: "/2fa/verify",
element: ,
},
{
path: "/reset-password/change-password",
element: ,
},
{
path: "/verification-account",
element: ,
},
{
path: "/registration",
element: ,
},
{
path: "/apply-registration",
element: ,
},
// {
// path: "/quiz-registration",
// element: ,
// },
{
path: "/quiz-registration",
element: ,
},
{
path: "/connect-plaid",
element: ,
},
{
path: "plaid-processing",
element: } />,
},
{
path: "request-in-progress",
element: } />,
},
{
path: "/google/callback",
element: ,
},
{
path: "/partner-registration",
element: ,
},
// Legal pages (accessible to all users)
{
path: "/privacy-policy",
element: ,
},
{
path: "/terms-of-service",
element: ,
},
];
export const router = createBrowserRouter([
...publicRoutes,
// Error routes
{
path: "/error",
element: ,
},
// 404 catch-all route (must be last)
{
path: "*",
element: ,
},
]);