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

import { AppShell } from "./components/app-shell";
import { ProtectedRoute } from "./components/protected-route";
import { HomePage } from "./pages/DashboardPage";
import { LoginRedirectPage, NotFoundPage } from "./pages/PlaceholderPage";
import { ProfilePage } from "./pages/ProfilePage";
import { ProjectsPage } from "./pages/ProjectsPage";
import { GitRepositoriesPage } from "./pages/GitRepositoriesPage";
import { GitHistoryPage } from "./pages/GitHistoryPage";
import { ProjectSettingsPage } from "./pages/ProjectSettingsPage";
import { SettingsPage, GeneralSettingsTab } from "./pages/SettingsPage";
import { TerminalPage } from "./pages/TerminalPage";
import { ToolWorkshopPage } from "./pages/ToolWorkshopPage";
import { SSHKeysPage } from "./pages/SshKeysPage";
import { ConfigProfilesPage } from "./pages/ConfigProfilesPage";
import { SessionsPage } from "./pages/SessionsPage";
import { WorkspacesPage } from "./pages/WorkspacesPage";
import { WorkspaceDetailPage } from "./pages/WorkspaceDetailPage";

export const AppRouter = () => {
	return (
		<Routes>
			<Route path="/login" element={<LoginRedirectPage />} />
			<Route
				path="/ssh-keys"
				element={<Navigate to="/settings/ssh-keys" replace />}
			/>
			<Route
				path="/"
				element={
					<ProtectedRoute>
						<AppShell />
					</ProtectedRoute>
				}
			>
				<Route index element={<HomePage />} />
				<Route path="projects" element={<ProjectsPage />} />
				<Route
					path="projects/:projectId/repositories"
					element={<GitRepositoriesPage />}
				/>
				<Route
					path="projects/:projectId/repositories/:repoId/history"
					element={<GitHistoryPage />}
				/>
				<Route
					path="projects/:projectId/settings/*"
					element={<ProjectSettingsPage />}
				/>
				<Route path="profile" element={<ProfilePage />} />
				<Route path="config-profiles" element={<ConfigProfilesPage />} />
				<Route path="settings" element={<SettingsPage />}>
					<Route index element={<Navigate to="general" replace />} />
					<Route path="general" element={<GeneralSettingsTab />} />
					<Route path="ssh-keys" element={<SSHKeysPage />} />
					<Route path="*" element={<Navigate to="general" replace />} />
				</Route>
				<Route path="sessions" element={<SessionsPage />} />
				<Route path="workspaces" element={<WorkspacesPage />} />
				<Route
					path="workspaces/:workspaceId"
					element={<WorkspaceDetailPage />}
				/>
				<Route path="tool-workshop" element={<ToolWorkshopPage />} />
				<Route
					path="instances/:instanceId/terminal"
					element={<TerminalPage />}
				/>
			</Route>
			<Route path="/404" element={<NotFoundPage />} />
			<Route path="*" element={<Navigate to="/404" replace />} />
		</Routes>
	);
};
