import type { MockMethod } from 'vite-plugin-mock';

const routes: AuthRoute.Route[] = [
  {
    name: 'home',
    path: '/home',
    component: 'self',
    meta: {
      title: '首页',
      requiresAuth: true,
      singleLayout: 'basic',
      icon: 'tabler:home-2',
      order: 0
    }
  },
  {
    name: 'exception',
    path: '/exception',
    component: 'basic',
    children: [
      {
        name: 'exception_403',
        path: '/exception/403',
        component: 'self',
        meta: {
          title: '异常页403',
          requiresAuth: true,
          icon: 'ic:baseline-block'
        }
      },
      {
        name: 'exception_404',
        path: '/exception/404',
        component: 'self',
        meta: {
          title: '异常页404',
          requiresAuth: true,
          icon: 'ic:baseline-web-asset-off'
        }
      },
      {
        name: 'exception_500',
        path: '/exception/500',
        component: 'self',
        meta: {
          title: '异常页500',
          requiresAuth: true,
          icon: 'ic:baseline-wifi-off'
        }
      }
    ],
    meta: {
      title: '异常页',
      icon: 'ant-design:exception-outlined',
      order: 5
    }
  }
];

function dataMiddleware(data: AuthRoute.Route[]): AuthRoute.Route[] {
  // const routeHomeName: AuthRoute.RouteKey = 'home';

  function sortRoutes(sorts: AuthRoute.Route[]) {
    return sorts.sort((next, pre) => Number(next.meta?.order) - Number(pre.meta?.order));
  }

  return sortRoutes(data);
}

const apis: MockMethod[] = [
  {
    url: '/mock/getRouters',
    method: 'get',
    response: (): Service.MockServiceResult => {
      return {
        code: 200,
        message: 'ok',
        data: dataMiddleware(routes)
      };
    }
  }
];

export default apis;
