import { createBrowserRouter, createHashRouter } from "react-router-dom";
import { lazy, Suspense, type ReactNode } from "react";
import { AppLayout } from "@/components/layout/AppLayout";
import {
DashboardSkeleton,
HomeSkeleton,
LibrarySkeleton,
WatchlistSkeleton,
CollectionsSkeleton,
CollectionDetailsSkeleton,
EntryDetailsSkeleton,
SeasonSkeleton,
EpisodeSkeleton,
PeopleSkeleton,
PersonDetailsSkeleton,
MediaSkeleton,
CalendarSkeleton,
SettingsSkeleton,
DiscoveryVideosSkeleton,
} from "@/components/skeletons/PageSkeletons";
// Lazy-loaded pages
const HomePage = lazy(() =>
import("@/pages/HomePage").then((m) => ({ default: m.HomePage })),
);
const DashboardPage = lazy(() =>
import("@/pages/DashboardPage").then((m) => ({ default: m.DashboardPage })),
);
const HistoryPage = lazy(() =>
import("@/pages/HistoryPage").then((m) => ({ default: m.HistoryPage })),
);
const LibraryPage = lazy(() =>
import("@/pages/LibraryPage").then((m) => ({ default: m.LibraryPage })),
);
const WatchlistPage = lazy(() =>
import("@/pages/WatchlistPage").then((m) => ({ default: m.WatchlistPage })),
);
const CollectionsPage = lazy(() =>
import("@/pages/CollectionsPage").then((m) => ({
default: m.CollectionsPage,
})),
);
const CollectionDetailsPage = lazy(() =>
import("@/pages/CollectionDetailsPage").then((m) => ({
default: m.CollectionDetailsPage,
})),
);
const MediaPage = lazy(() =>
import("@/pages/MediaPage").then((m) => ({ default: m.MediaPage })),
);
const CalendarPage = lazy(() =>
import("@/pages/CalendarPage").then((m) => ({ default: m.CalendarPage })),
);
const EntryDetailsPage = lazy(() =>
import("@/pages/EntryDetailsPage").then((m) => ({
default: m.EntryDetailsPage,
})),
);
const TmdbCastsPage = lazy(() =>
import("@/pages/TmdbCastsPage").then((m) => ({
default: m.TmdbCastsPage,
})),
);
const SeasonPage = lazy(() =>
import("@/pages/SeasonPage").then((m) => ({ default: m.SeasonPage })),
);
const EpisodePage = lazy(() =>
import("@/pages/EpisodePage").then((m) => ({ default: m.EpisodePage })),
);
const EntryCastsPage = lazy(() =>
import("@/pages/EntryCastsPage").then((m) => ({
default: m.EntryCastsPage,
})),
);
const PeoplePage = lazy(() =>
import("@/pages/PeoplePage").then((m) => ({ default: m.PeoplePage })),
);
const WatchBuddiesPage = lazy(() =>
import("@/pages/WatchBuddiesPage").then((m) => ({
default: m.WatchBuddiesPage,
})),
);
const WatchBuddyProfilePage = lazy(() =>
import("@/pages/WatchBuddyProfilePage").then((m) => ({
default: m.WatchBuddyProfilePage,
})),
);
const PersonDetailsPage = lazy(() =>
import("@/pages/PersonDetailsPage").then((m) => ({
default: m.PersonDetailsPage,
})),
);
const SettingsPage = lazy(() =>
import("@/pages/SettingsPage").then((m) => ({ default: m.SettingsPage })),
);
const DiscoveryVideosPage = lazy(() =>
import("@/pages/DiscoveryVideosPage").then((m) => ({
default: m.DiscoveryVideosPage,
})),
);
const DiscoverPage = lazy(() =>
import("@/pages/DiscoverPage").then((m) => ({ default: m.DiscoverPage })),
);
const SearchPage = lazy(() =>
import("@/pages/SearchPage").then((m) => ({ default: m.SearchPage })),
);
function SuspensePage({
children,
fallback,
}: {
children: ReactNode;
fallback?: ReactNode;
}) {
return (
}>{children}
);
}
const isElectron = import.meta.env.VITE_ELECTRON === "true";
const createRouter = isElectron ? createHashRouter : createBrowserRouter;
export const router = createRouter([
{
element: ,
children: [
{
path: "/",
element: (
}>
),
},
{
path: "/search",
element: (
}>
),
},
{
path: "/dashboard",
element: (
}>
),
},
{
path: "/library",
element: (
}>
),
},
{
path: "/discover/:category",
element: (
}>
),
},
{
path: "/history",
element: (
}>
),
},
{
path: "/watchlist",
element: (
}>
),
},
{
path: "/collections",
element: (
}>
),
},
{
path: "/collections/:id",
element: (
}>
),
},
{
path: "/media",
element: (
}>
),
},
{
path: "/discovery-videos",
element: (
}>
),
},
{
path: "/calendar",
element: (
}>
),
},
{
path: "/entry/tmdb/:type/:tmdbId/cast",
element: (
}>
),
},
{
path: "/entry/tmdb/:type/:tmdbId",
element: (
}>
),
},
{
path: "/entry/:id",
element: (
}>
),
},
{
path: "/entry/:id/cast",
element: (
}>
),
},
{
path: "/entry/:entryId/season/:seasonId",
element: (
}>
),
},
{
path: "/entry/:entryId/season/:seasonId/episode/:episodeId",
element: (
}>
),
},
{
path: "/people",
element: (
}>
),
},
{
path: "/people/tmdb/:tmdbId",
element: (
}>
),
},
{
path: "/people/:id",
element: (
}>
),
},
{
path: "/watch-buddies",
element: (
}>
),
},
{
path: "/watch-buddies/:id",
element: (
}>
),
},
{
path: "/settings",
element: (
}>
),
},
],
},
]);