import { createBrowserRouter, Navigate } from 'react-router';
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 { LoginPage } from './pages/Login';

// 多租户UI包导入
import { UserManagement } from '@d8d/user-management-ui-mt';
import { AuthManagement } from '@d8d/auth-management-ui-mt';
import { FileManagement } from '@d8d/file-management-ui-mt';
import { AreaManagement } from '@d8d/area-management-ui-mt';
import { SupplierManagement } from '@d8d/supplier-management-ui-mt';
import { MerchantManagement } from '@d8d/merchant-management-ui-mt';
import { OrderManagement } from '@d8d/order-management-ui-mt';
import { AdvertisementTypeManagement } from '@d8d/advertisement-type-management-ui-mt';
import { GoodsManagement } from '@d8d/goods-management-ui-mt';
import { GoodsCategoryManagement } from '@d8d/goods-category-management-ui-mt';
import { DeliveryAddressManagement } from '@d8d/delivery-address-management-ui-mt';
import { AdvertisementManagement } from '@d8d/advertisement-management-ui-mt';

import "@/client/api_init"

export const router = createBrowserRouter([
  {
    path: '/',
    element: <Navigate to="/admin" replace />
  },
  {
    path: '/admin/login',
    element: <LoginPage />
  },
  {
    path: '/admin',
    element: (
      <ProtectedRoute>
        <MainLayout />
      </ProtectedRoute>
    ),
    children: [
      {
        index: true,
        element: <Navigate to="/admin/dashboard" />
      },
      {
        path: 'dashboard',
        element: <DashboardPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'users',
        element: <UserManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'auth',
        element: <AuthManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'files',
        element: <FileManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'areas',
        element: <AreaManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'advertisements',
        element: <AdvertisementManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'advertisement-types',
        element: <AdvertisementTypeManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'goods-categories',
        element: <GoodsCategoryManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'goods',
        element: <GoodsManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'suppliers',
        element: <SupplierManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'merchants',
        element: <MerchantManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'delivery-addresses',
        element: <DeliveryAddressManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'orders',
        element: <OrderManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: '*',
        element: <NotFoundPage />,
        errorElement: <ErrorPage />
      },
    ],
  },
  {
    path: '*',
    element: <NotFoundPage />,
    errorElement: <ErrorPage />
  },
]);