if (import.meta.env.MODE !== "production") {
  // Loading eruda dynamically to avoid bundling it in production
  // Awaiting eruda initialization to start logs recording as soon as possible
  const { default: eruda } = await import("eruda");
  eruda.init();
  eruda.position({ x: 8, y: window.innerHeight / 3 });
}

import { StrictMode } from "react";
import ReactDOM from "react-dom/client";
import { RouterProvider, createRouter } from "@tanstack/react-router";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";

import i18n from "@/i18n";
import tg from "@/tg";
import { routeTree } from "./routeTree.gen";
import { AudioProvider } from "@/audio";
import { LiftProvider } from "@components/lift";

import "./styles/index.css";

const router = createRouter({ routeTree });

// Register the router instance for type safety
declare module "@tanstack/react-router" {
  interface Register {
    router: typeof router;
  }
}

tg.init();
i18n.init();

ReactDOM.createRoot(document.getElementById("root")!).render(
  <StrictMode>
    <QueryClientProvider client={new QueryClient()}>
      <AudioProvider>
        <LiftProvider>
          <RouterProvider router={router} />
        </LiftProvider>
      </AudioProvider>
    </QueryClientProvider>
  </StrictMode>,
);
