import React from "react";
import ReactDOM from "react-dom/client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { WagmiProvider } from "wagmi";
import { RainbowKitProvider, darkTheme } from "@rainbow-me/rainbowkit";
import "./index.css";
import "@rainbow-me/rainbowkit/styles.css";
import { wagmiConfig } from "./wagmiConfig";

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>
      <WagmiProvider config={wagmiConfig}>
        <QueryClientProvider client={queryClient}>
          <RainbowKitProvider
            theme={darkTheme({
              accentColor: "#d4af37",
              accentColorForeground: "#0a0a0a",
              borderRadius: "medium",
            })}
            modalSize="wide"
          >
            <App />
          </RainbowKitProvider>
        </QueryClientProvider>
      </WagmiProvider>
    </React.StrictMode>,
  );
})();
