import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { HashRouter } from "react-router";
import { TRPCProvider } from "@/providers/trpc";
import App from "./App";
import "./index.css";

// Read the initial route set by the static HTML page
const initialRoute = (window as any).__INITIAL_ROUTE__ || "/";

// If we have an initial route from the static page, use it as the HashRouter entry
const routerProps = initialRoute !== "/"
  ? { initialEntries: [initialRoute] as [string] }
  : {};

createRoot(document.getElementById("root")!).render(
  <StrictMode>
    <TRPCProvider>
      <HashRouter {...routerProps}>
        <App />
      </HashRouter>
    </TRPCProvider>
  </StrictMode>
);
