import { createBrowserRouter, Navigate } from 'react-router-dom';
import { ProtectedRoute } from './components/ProtectedRoute';
import { MainLayout } from './layouts/MainLayout';
import { ErrorPage } from './components/ErrorPage';
import { NotFoundPage } from './components/NotFoundPage';
import { DashboardPage } from './pages/Dashboard';
import { TenantLoginPage } from '@d8d/tenant-management-ui';

// 租户管理UI包导入
import { TenantsPage, TenantConfigPage } from '@d8d/tenant-management-ui';

import "./api_init"

export const router = createBrowserRouter([
  {
    path: '/',
    element: <Navigate to="/tenant" replace />
  },
  {
    path: '/tenant/login',
    element: <TenantLoginPage />
  },
  {
    path: '/tenant',
    element: (
      <ProtectedRoute>
        <MainLayout />
      </ProtectedRoute>
    ),
    children: [
      {
        index: true,
        element: <Navigate to="/tenant/dashboard" />
      },
      {
        path: 'dashboard',
        element: <DashboardPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'tenants',
        element: <TenantsPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'config/:id',
        element: <TenantConfigPage />,
        errorElement: <ErrorPage />
      },
      // {
      //   path: 'analytics',
      //   element: <DashboardPage />, // 暂时使用DashboardPage，后续可替换为专门的AnalyticsPage
      //   errorElement: <ErrorPage />
      // },
      // {
      //   path: 'profile',
      //   element: <DashboardPage />, // 暂时使用DashboardPage，后续可替换为专门的ProfilePage
      //   errorElement: <ErrorPage />
      // },
      // {
      //   path: 'account-settings',
      //   element: <DashboardPage />, // 暂时使用DashboardPage，后续可替换为专门的AccountSettingsPage
      //   errorElement: <ErrorPage />
      // },
      {
        path: '*',
        element: <NotFoundPage />,
        errorElement: <ErrorPage />
      },
    ],
  },
  {
    path: '*',
    element: <NotFoundPage />,
    errorElement: <ErrorPage />
  },
]);