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

import { NotFoundPage } from "@/components/not-found.page";
import { ObjectsPage } from "@/modules/watcher/objects/ObjectsPage";
import { WatcherSubscriptions } from "@/modules/watcher/WatcherSubscriptions";
import { WelcomeDialog } from "@/modules/watcher/WelcomeDialog";
import { AnalyticsPage } from "@/pages/AnalyticsPage";
import { ReportsPage } from "@/pages/ReportsPage";
import { AlarmManagementProvider } from "@/providers/alarms/AlarmManagementProvider";

export const WatcherLayout = () => {
	const [isShowWelcomeDialog, setIsShowWelcomeDialog] = useState(true);

	if (isShowWelcomeDialog) {
		return <WelcomeDialog onClose={() => setIsShowWelcomeDialog(false)} />;
	}

	return (
		<>
			<Routes>
				<Route index element={<Navigate to="objects" replace />} />
				<Route path="objects" Component={ObjectsPage} />
				<Route path="reports" Component={ReportsPage} />
				<Route path="analytics" Component={AnalyticsPage} />
				<Route path="*" element={<NotFoundPage />} />
			</Routes>

			<AlarmManagementProvider />

			<WatcherSubscriptions />
		</>
	);
};
