import { createBrowserRouter } from "react-router-dom";
import AppLayout from "../components/layout/AppLayout";
import ApiKeyCreatePage from "../features/api-keys/ApiKeyCreatePage";
import ApiKeyListPage from "../features/api-keys/ApiKeyListPage";
import AuditLogsPage from "../features/audit/AuditLogsPage";
import AuthCallbackPage from "../features/auth/AuthCallbackPage";
import AuthPage from "../features/auth/AuthPage";
import LoginPage from "../features/auth/LoginPage";
import GlobalOverviewPage from "../features/overview/GlobalOverviewPage";
import { TenantAdminsAndOwnersTab } from "../features/tenants/routes/TenantAdminsAndOwnersTab";
import TenantCreatePage from "../features/tenants/routes/TenantCreatePage";
import TenantDetailPage from "../features/tenants/routes/TenantDetailPage";
import TenantListPage from "../features/tenants/routes/TenantListPage";
import { TenantProfilePage } from "../features/tenants/routes/TenantProfilePage";
import { TenantSchemaPage } from "../features/tenants/routes/TenantSchemaPage";
import TenantUserGroupsTab from "../features/user-groups/routes/TenantUserGroupsTab";
import { UserGroupDetailPage } from "../features/user-groups/routes/UserGroupDetailPage";
import UserCreatePage from "../features/users/UserCreatePage";
import UserDetailPage from "../features/users/UserDetailPage";
import UserListPage from "../features/users/UserListPage";

export const router = createBrowserRouter(
  [
    {
      path: "/login",
      element: <LoginPage />,
    },
    {
      path: "/auth/callback",
      element: <AuthCallbackPage />,
    },
    {
      path: "/",
      element: <AppLayout />,
      children: [
        { index: true, element: <GlobalOverviewPage /> },
        { path: "audit-logs", element: <AuditLogsPage /> },
        { path: "auth", element: <AuthPage /> },
        { path: "users", element: <UserListPage /> },
        { path: "users/new", element: <UserCreatePage /> },
        { path: "users/:id", element: <UserDetailPage /> },
        { path: "tenants", element: <TenantListPage /> },
        { path: "tenants/new", element: <TenantCreatePage /> },
        {
          path: "tenants/:tenantId",
          element: <TenantDetailPage />,
          children: [
            { index: true, element: <TenantProfilePage /> },
            { path: "permissions", element: <TenantAdminsAndOwnersTab /> },
            { path: "organization", element: <TenantUserGroupsTab /> },
            { path: "schema", element: <TenantSchemaPage /> },
          ],
        },
        {
          path: "tenants/:tenantId/organization/:id",
          element: <TenantUserGroupsTab />,
        },
        { path: "api-keys", element: <ApiKeyListPage /> },
        { path: "api-keys/new", element: <ApiKeyCreatePage /> },
      ],
    },
  ],
  // React Router v7 플래그는 Provider에서 적용합니다.
);
