import React from "react";
import ReactDOM from "react-dom/client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import "./index.css";

const queryClient = new QueryClient();

const adminOnly = import.meta.env.VITE_ADMIN_ONLY === "true";

void (async () => {
  const root = document.getElementById("root")!;

  if (adminOnly) {
    const { default: AppAdminOnly } = await import("./AppAdminOnly");
    ReactDOM.createRoot(root).render(
      <React.StrictMode>
        <AppAdminOnly />
      </React.StrictMode>,
    );
    return;
  }

  const { default: App } = await import("./App");
  ReactDOM.createRoot(root).render(
    <React.StrictMode>
      <QueryClientProvider client={queryClient}>
        <App />
      </QueryClientProvider>
    </React.StrictMode>,
  );
})();
