import { lazy, Suspense } from "react";
import SignIn from "./auth/SignIn";
import { useLocation } from "./router";
import InviteLanding from "./site/InviteLanding";
import Landing from "./site/Landing";
import RequestAccess from "./site/RequestAccess";
import { Spinner } from "./ui";
// The signed-out site loads first; the clinician screens and Try a fictional patient load on demand.
const AppRoutes = lazy(() => import("./AppRoutes"));
const DemoApp = lazy(() => import("../demo/DemoApp"));
/** The routes of context.marmar.life. */
export default function Root() {
const { path } = useLocation();
const loading = (
<div className="flex min-h-dvh items-center justify-center bg-frame">
<Spinner label="Opening Context" />
</div>
);
// ACC-11: the old reviewer preview (shared password, model connection) exists only on the Vite
// dev server. import.meta.env.DEV is the literal false in any build, so the route is not in it.
if (path === "/demo" || (import.meta.env.DEV && path === "/preview"))
return (
<Suspense fallback={loading}>
<DemoApp readOnly={path === "/demo"} />
</Suspense>
);
if (path.startsWith("/invite/")) return <InviteLanding token={decodeURIComponent(path.slice("/invite/".length))} />;
if (path === "/request-access") return <RequestAccess />;
if (path === "/sign-in") return <SignIn />;
if (path === "/app" || path.startsWith("/app/"))
return (
<Suspense fallback={loading}>
<AppRoutes path={path} />
</Suspense>
);
return <Landing />;
}