import { Suspense, lazy } from "react";
import { Navigate, Outlet, RouterProvider, createBrowserRouter } from "react-router-dom";
import { LoadingOverlay, ProtectedRoute } from "./components";
// Lazy load components
const DealerLayout = lazy(() => import("./app").then((m) => ({ default: m.DealerLayout })));
const DealersList = lazy(() => import("./app").then((m) => ({ default: m.DealersList })));
const ErrorPage = lazy(() => import("./app").then((m) => ({ default: m.ErrorPage })));
const LoginPageWithLanguageSelector = lazy(() =>
import("./app").then((m) => ({ default: m.LoginPageWithLanguageSelector }))
);
const LogoutPage = lazy(() => import("./app").then((m) => ({ default: m.LogoutPage })));
const QuoteCreate = lazy(() => import("./app").then((m) => ({ default: m.QuoteCreate })));
const QuoteEdit = lazy(() => import("./app").then((m) => ({ default: m.QuoteEdit })));
const SettingsEditor = lazy(() => import("./app").then((m) => ({ default: m.SettingsEditor })));
const SettingsLayout = lazy(() => import("./app").then((m) => ({ default: m.SettingsLayout })));
const CatalogLayout = lazy(() => import("./app").then((m) => ({ default: m.CatalogLayout })));
const CatalogList = lazy(() => import("./app").then((m) => ({ default: m.CatalogList })));
const DashboardPage = lazy(() => import("./app").then((m) => ({ default: m.DashboardPage })));
const QuotesLayout = lazy(() => import("./app").then((m) => ({ default: m.QuotesLayout })));
const QuotesList = lazy(() => import("./app").then((m) => ({ default: m.QuotesList })));
export const Routes = () => {
const routesForErrors = [
{
path: "*",
Element: (
}>
),
},
];
// Define routes accessible only to authenticated users
const routesForAuthenticatedOnly = [
{
path: "/",
element: (
),
},
{
path: "/home",
element: (
}>
),
},
{
path: "/catalog",
element: (
}>
),
children: [
{
index: true,
element: (
}>
),
},
],
},
{
path: "/dealers",
element: (
}>
),
children: [
{
index: true,
element: (
}>
),
},
],
},
{
path: "/quotes",
element: (
}>
),
children: [
{
index: true,
element: (
}>
),
},
{
path: "add",
element: (
}>
),
},
{
path: "edit/:id",
element: (
}>
),
},
],
},
{
path: "/settings",
element: (
}>
),
children: [
{
index: true,
element: (
}>
),
},
],
},
{
path: "/logout",
element: ,
},
];
// Define routes accessible only to non-authenticated users
const routesForNotAuthenticatedOnly = [
{
path: "/login",
element: (
}>
),
},
];
// Combine and conditionally include routes based on authentication status
const router = createBrowserRouter(
[...routesForAuthenticatedOnly, ...routesForNotAuthenticatedOnly, ...routesForErrors],
{
//basename: "/app",
}
);
// Provide the router configuration using RouterProvider
return ;
};