import { DomainflareProvider, useDomainflare } from "./context/DomainflareContext";
import { AppSplash } from "./components/AppSplash";
import { Gate } from "./components/Gate";
import { MainLayout } from "./components/MainLayout";
import { PwaUpdatePrompt } from "./components/PwaUpdatePrompt";
import { ToastHost } from "./components/ToastHost";

function Shell() {
  const { unlocked } = useDomainflare();
  return (
    <>
      {!unlocked ? <Gate /> : null}
      {unlocked ? <MainLayout /> : null}
    </>
  );
}

function AppBody() {
  const { sessionBootstrapDone } = useDomainflare();
  return (
    <>
      {!sessionBootstrapDone ? <AppSplash /> : <Shell />}
      <ToastHost />
      <PwaUpdatePrompt />
    </>
  );
}

export function App() {
  return (
    <DomainflareProvider>
      <AppBody />
    </DomainflareProvider>
  );
}
