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

import { AppShell } from "./components/app-shell";
import { ProtectedRoute } from "./components/protected-route";
import { HomePage } from "./pages/dashboard";
import { LoginRedirectPage, NotFoundPage } from "./pages/placeholder";
import { ProfilePage } from "./pages/profile";
import { ProjectsPage } from "./pages/projects";
import { GitRepositoriesPage } from "./pages/git-repositories";
import { GitHistoryPage } from "./pages/git-history";
import { ProjectSettingsPage } from "./pages/project-settings";
import { RepoWorkspace } from "./pages/repo-workspace";
import { SettingsPage, GeneralSettingsTab } from "./pages/settings";
import { TerminalPage } from "./pages/terminal";
import { ToolWorkshopPage } from "./pages/tool-workshop";
import { SSHKeysPage } from "./pages/ssh-keys";
import { ConfigProfilesPage } from "./pages/config-profiles";
import { SessionsPage } from "./pages/sessions";

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" element={<RepoWorkspace />} />
        <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="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>
  );
};
