import { Suspense, lazy } from "react";
import { Navigate, Route, Routes } from "react-router-dom";
import { Shell } from "../components/Shell";
import { LoadingBlock } from "../components/StateBlock";

const OverviewPage = lazy(() => import("../pages/OverviewPage"));
const RepositoriesPage = lazy(() => import("../pages/RepositoriesPage"));
const RepositoryDetailPage = lazy(() => import("../pages/RepositoryDetailPage"));
const PublicationPointsPage = lazy(() => import("../pages/PublicationPointsPage"));
const PublicationPointDetailPage = lazy(
  () => import("../pages/PublicationPointDetailPage"),
);
const ObjectsPage = lazy(() => import("../pages/ObjectsPage"));
const ObjectDetailPage = lazy(() => import("../pages/ObjectDetailPage"));
const ValidationPage = lazy(() => import("../pages/ValidationPage"));
const SearchPage = lazy(() => import("../pages/SearchPage"));
const ExportsPage = lazy(() => import("../pages/ExportsPage"));
const RunsPage = lazy(() => import("../pages/RunsPage"));
const ApiStatusPage = lazy(() => import("../pages/ApiStatusPage"));
const NotFoundPage = lazy(() => import("../pages/NotFoundPage"));

export function App() {
  return (
    <Shell>
      <Suspense fallback={<LoadingBlock label="Loading page…" />}>
        <Routes>
          <Route path="/" element={<OverviewPage />} />
          <Route path="/repositories" element={<RepositoriesPage />} />
          <Route path="/repositories/:repoId" element={<RepositoryDetailPage />} />
          <Route path="/publication-points" element={<PublicationPointsPage />} />
          <Route
            path="/publication-points/:ppId"
            element={<PublicationPointDetailPage />}
          />
          <Route path="/objects" element={<ObjectsPage />} />
          <Route path="/objects/:objectInstanceId" element={<ObjectDetailPage />} />
          <Route path="/validation" element={<ValidationPage />} />
          <Route path="/search" element={<SearchPage />} />
          <Route path="/exports" element={<ExportsPage />} />
          <Route path="/runs" element={<RunsPage />} />
          <Route path="/api" element={<ApiStatusPage />} />
          <Route path="/404" element={<NotFoundPage />} />
          <Route path="*" element={<Navigate to="/404" replace />} />
        </Routes>
      </Suspense>
    </Shell>
  );
}
