import { Navigate, Route, Routes } from "react-router-dom";

import { AuthorizedContextProvider } from "../contexts/authorized/AuthorizedContextProvider";
import { UnauthorizedContextProvider } from "../contexts/authorized/UnauthorizedContextProvider";
import { AdministratorRoutes } from "../modules/admin/AdministratorRoutes";
import { ManagerPage } from "../modules/manager/ManagerPage";
import { WatcherLayout } from "../pages/Watcher/ui/WatcherLayout";

import { AuthorizedRedirection } from "./AuthorizedRedirection";

export const AuthorizedRoutes = () => {
	return (
		<>
			<AuthorizedContextProvider>
				<AuthorizedRedirection />

				<Routes>
					<Route path="admin/*" Component={AdministratorRoutes} />
					<Route path="manager/*" Component={ManagerPage} />
					<Route path="watcher/*" Component={WatcherLayout} />
				</Routes>
			</AuthorizedContextProvider>

			<UnauthorizedContextProvider>
				<Navigate to="/login" />
			</UnauthorizedContextProvider>
		</>
	);
};
