import { createRoot } from "react-dom/client";
import { RouteObject, RouterProvider, createBrowserRouter } from "react-router-dom";
import App from "./App";
import { StrictMode, lazy } from "react";

const routes: RouteObject[] = [
  {
    path: "/",
    children: [
      {
        index: true,
        element: <App />,
      },
      {
        path: ":quizId",
        element: <App />,
      },
    ],
  },
];

if (import.meta.env.DEV) {
  const WidgetDev = lazy(() => import("./WidgetDev"));

  routes[0].children?.push({
    path: "widgetdev",
    element: <WidgetDev />,
  });
}

const router = createBrowserRouter(routes);

const root = createRoot(document.getElementById("root")!);

root.render(
  <StrictMode>
    <RouterProvider router={router} />
  </StrictMode>
);
