import {
  Navigate,
  type RouteObject,
  createBrowserRouter,
} from "react-router-dom";
import AuthCallbackPage from "../features/auth/AuthCallbackPage";
import AuthGuard from "../features/auth/AuthGuard";
import LoginPage from "../features/auth/LoginPage";
import { TenantOrgChartPage } from "../features/orgchart/routes/OrgChartPage";
import { OrgFrontLayout } from "../features/orgchart/routes/OrgFrontLayout";
import { OrgPickerEmbedPreviewPage } from "../features/orgchart/routes/OrgPickerEmbedPreviewPage";
import {
  OrgPickerEmbedPage,
  OrgPickerPage,
} from "../features/orgchart/routes/OrgPickerPage";
import { ORGFRONT_AUTH_CALLBACK_PATH } from "../lib/authConfig";

export const orgFrontRoutes: RouteObject[] = [
  {
    path: "/login",
    element: <LoginPage />,
  },
  {
    path: ORGFRONT_AUTH_CALLBACK_PATH,
    element: <AuthCallbackPage />,
  },
  {
    path: "/",
    element: <AuthGuard />,
    children: [
      { index: true, element: <Navigate to="/chart" replace /> },
      {
        element: <OrgFrontLayout />,
        children: [
          { path: "chart", element: <TenantOrgChartPage /> },
          { path: "chart/:tenantId", element: <TenantOrgChartPage /> },
          { path: "picker", element: <OrgPickerPage /> },
          { path: "embed-preview", element: <OrgPickerEmbedPreviewPage /> },
        ],
      },
      { path: "embed/picker", element: <OrgPickerEmbedPage /> },
    ],
  },
];

export const router = createBrowserRouter(orgFrontRoutes, {
  future: {
    v7_startTransition: true,
  },
} as unknown as Parameters<typeof createBrowserRouter>[1]);
