import { type RouteObject, createBrowserRouter } from "react-router-dom";
import AppLayout from "../components/layout/AppLayout";
import AuditLogsPage from "../features/audit/AuditLogsPage";
import AuthCallbackPage from "../features/auth/AuthCallbackPage";
import AuthGuard from "../features/auth/AuthGuard";
import LoginPage from "../features/auth/LoginPage";
import ClientConsentsPage from "../features/clients/ClientConsentsPage";
import ClientDetailsPage from "../features/clients/ClientDetailsPage";
import ClientGeneralPage from "../features/clients/ClientGeneralPage";
import ClientRelationsPage from "../features/clients/ClientRelationsPage";
import ClientsPage from "../features/clients/ClientsPage";
import GlobalOverviewPage from "../features/overview/GlobalOverviewPage";
import DeveloperRequestPage from "../features/developer-request/DeveloperRequestPage";
import ProfilePage from "../features/profile/ProfilePage";
import { DEVFRONT_AUTH_CALLBACK_PATH } from "../lib/authConfig";

export const devFrontRoutes: RouteObject[] = [
  {
    path: "/login",
    element: <LoginPage />,
  },
  {
    path: DEVFRONT_AUTH_CALLBACK_PATH,
    element: <AuthCallbackPage />,
  },
  {
    path: "/",
    element: <AuthGuard />,
    children: [
      {
        element: <AppLayout />,
        children: [
          { index: true, element: <GlobalOverviewPage /> },
          { path: "clients", element: <ClientsPage /> },
          { path: "clients/new", element: <ClientGeneralPage /> },
          { path: "clients/:id", element: <ClientDetailsPage /> },
          { path: "clients/:id/consents", element: <ClientConsentsPage /> },
          { path: "clients/:id/settings", element: <ClientGeneralPage /> },
          {
            path: "clients/:id/relationships",
            element: <ClientRelationsPage />,
          },
          { path: "developer-requests", element: <DeveloperRequestPage /> },
          { path: "audit-logs", element: <AuditLogsPage /> },
          { path: "profile", element: <ProfilePage /> },
        ],
      },
    ],
  },
];

export const router = createBrowserRouter(
  devFrontRoutes,
  // React Router v7 플래그 사전 적용 (현재 타입 정의에 없어 any 캐스팅)
  {
    future: {
      v7_startTransition: true,
    },
  } as unknown as Parameters<typeof createBrowserRouter>[1],
);
