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';
import { AuthManagement } from '@d8d/auth-management-ui';
import { FileManagement } from '@d8d/file-management-ui';
import { AreaManagement } from '@d8d/area-management-ui';
import { BankNameManagement } from '@d8d/bank-name-management-ui';

// Allin系统UI包导入
import { ChannelManagement } from '@d8d/allin-channel-management-ui';
import { CompanyManagement } from '@d8d/allin-company-management-ui';
import { DisabilityPersonManagement } from '@d8d/allin-disability-person-management-ui';
import { OrderManagement } from '@d8d/allin-order-management-ui';
import { PlatformManagement } from '@d8d/allin-platform-management-ui';
import { SalaryManagement } from '@d8d/allin-salary-management-ui';

import "./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/users" />
      },
      {
        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: 'bank-names',
        element: <BankNameManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'channels',
        element: <ChannelManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'companies',
        element: <CompanyManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'disabilities',
        element: <DisabilityPersonManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'orders',
        element: <OrderManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'platforms',
        element: <PlatformManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: 'salaries',
        element: <SalaryManagement />,
        errorElement: <ErrorPage />
      },
      {
        path: '*',
        element: <NotFoundPage />,
        errorElement: <ErrorPage />
      },
    ],
  },
  {
    path: '*',
    element: <NotFoundPage />,
    errorElement: <ErrorPage />
  },
]);