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

import "./i18n/i18n";

const routes: RouteObject[] = [
  {
    path: "/",
    children: [
      {
        path: ":lang?", // Опциональный языковой сегмент
        children: [
          {
            index: true,
            element: <App />,
          },
          {
            path: ":quizId", // ID квиза
            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>
);
