import { useBadges } from "@/apis/hooks";
import App from "@/App";
import Lazy from "@/components/Lazy";
import { useEnabledStatus } from "@/modules/redux/hooks";
import BlacklistMoviesView from "@/pages/Blacklist/Movies";
import BlacklistSeriesView from "@/pages/Blacklist/Series";
import Episodes from "@/pages/Episodes";
import MoviesHistoryView from "@/pages/History/Movies";
import SeriesHistoryView from "@/pages/History/Series";
import MovieView from "@/pages/Movies";
import MovieDetailView from "@/pages/Movies/Details";
import MovieMassEditor from "@/pages/Movies/Editor";
import SeriesView from "@/pages/Series";
import SeriesMassEditor from "@/pages/Series/Editor";
import SettingsGeneralView from "@/pages/Settings/General";
import SettingsLanguagesView from "@/pages/Settings/Languages";
import SettingsNotificationsView from "@/pages/Settings/Notifications";
import SettingsProvidersView from "@/pages/Settings/Providers";
import SettingsRadarrView from "@/pages/Settings/Radarr";
import SettingsSchedulerView from "@/pages/Settings/Scheduler";
import SettingsSonarrView from "@/pages/Settings/Sonarr";
import SettingsSubtitlesView from "@/pages/Settings/Subtitles";
import SettingsUIView from "@/pages/Settings/UI";
import SystemBackupsView from "@/pages/System/Backups";
import SystemLogsView from "@/pages/System/Logs";
import SystemProvidersView from "@/pages/System/Providers";
import SystemReleasesView from "@/pages/System/Releases";
import SystemTasksView from "@/pages/System/Tasks";
import WantedMoviesView from "@/pages/Wanted/Movies";
import WantedSeriesView from "@/pages/Wanted/Series";
import { Environment } from "@/utilities";
import {
faClock,
faExclamationTriangle,
faFileExcel,
faFilm,
faLaptop,
faPlay,
} from "@fortawesome/free-solid-svg-icons";
import React, {
createContext,
FunctionComponent,
lazy,
useContext,
useMemo,
} from "react";
import { BrowserRouter } from "react-router-dom";
import Redirector from "./Redirector";
import { CustomRouteObject } from "./type";
const HistoryStats = lazy(() => import("@/pages/History/Statistics"));
const SystemStatusView = lazy(() => import("@/pages/System/Status"));
const Authentication = lazy(() => import("@/pages/Authentication"));
const NotFound = lazy(() => import("@/pages/404"));
function useRoutes(): CustomRouteObject[] {
const { data } = useBadges();
const { sonarr, radarr } = useEnabledStatus();
return useMemo(
() => [
{
path: "/",
element: ,
children: [
{
index: true,
element: ,
},
{
icon: faPlay,
name: "Series",
path: "series",
hidden: !sonarr,
children: [
{
index: true,
element: ,
},
{
path: "edit",
hidden: true,
element: ,
},
{
path: ":id",
element: ,
},
],
},
{
icon: faFilm,
name: "Movies",
path: "movies",
hidden: !radarr,
children: [
{
index: true,
element: ,
},
{
path: "edit",
hidden: true,
element: ,
},
{
path: ":id",
element: ,
},
],
},
{
icon: faClock,
name: "History",
path: "history",
hidden: !sonarr && !radarr,
children: [
{
path: "series",
name: "Episodes",
hidden: !sonarr,
element: ,
},
{
path: "movies",
name: "Movies",
hidden: !radarr,
element: ,
},
{
path: "stats",
name: "Statistics",
element: (
),
},
],
},
{
icon: faExclamationTriangle,
name: "Wanted",
path: "wanted",
hidden: !sonarr && !radarr,
children: [
{
name: "Episodes",
path: "series",
badge: data?.episodes,
hidden: !sonarr,
element: ,
},
{
name: "Movies",
path: "movies",
badge: data?.movies,
hidden: !radarr,
element: ,
},
],
},
{
icon: faFileExcel,
name: "Blacklist",
path: "blacklist",
hidden: !sonarr && !radarr,
children: [
{
path: "series",
name: "Episodes",
hidden: !sonarr,
element: ,
},
{
path: "movies",
name: "Movies",
hidden: !radarr,
element: ,
},
],
},
{
icon: faExclamationTriangle,
name: "Settings",
path: "settings",
children: [
{
path: "general",
name: "General",
element: ,
},
{
path: "languages",
name: "Languages",
element: ,
},
{
path: "providers",
name: "Providers",
element: ,
},
{
path: "subtitles",
name: "Subtitles",
element: ,
},
{
path: "sonarr",
name: "Sonarr",
element: ,
},
{
path: "radarr",
name: "Radarr",
element: ,
},
{
path: "notifications",
name: "Notifications",
element: (
),
},
{
path: "scheduler",
name: "Scheduler",
element: ,
},
{
path: "ui",
name: "UI",
element: ,
},
],
},
{
icon: faLaptop,
name: "System",
path: "system",
children: [
{
path: "tasks",
name: "Tasks",
element: ,
},
{
path: "logs",
name: "Logs",
element: ,
},
{
path: "providers",
name: "Providers",
badge: data?.providers,
element: ,
},
{
path: "backup",
name: "Backups",
element: ,
},
{
path: "status",
name: "Status",
element: (
),
},
{
path: "releases",
name: "Releases",
element: ,
},
],
},
],
},
{
path: "/login",
hidden: true,
element: (
),
},
{
path: "*",
hidden: true,
element: (
),
},
],
[data?.episodes, data?.movies, data?.providers, radarr, sonarr]
);
}
const RouterItemContext = createContext([]);
export const Router: FunctionComponent = ({ children }) => {
const routes = useRoutes();
return (
{children}
);
};
export function useRouteItems() {
return useContext(RouterItemContext);
}