import {
  intendantRouter
} from '@/config/intendant'
import {
  deliverymanRouter
} from '@/config/deliveryman'
import {
  iceRouter
} from '@/config/iceManagement'
// 前端未找到页面路由（固定不用改）
const notFoundRouter = {
  name: 'FourOhFour',
  path: '*',
  redirect: '/FourOhFour',
  hidden: true
}
const companyRouter = {
  name: 'index',
  path: '/',
  component: () => import('@/views/common/Base'),
  redirect: '/home',
  children: [{
      path: '/home',
      name: 'home',
      meta: {
        icon: 'icon-shouye',
        title: '首页'
      },
      component: () => import('@/views/page/Home'),
    },
    // {
    //   path: '/UserManagement',
    //   name: 'UserManagement',
    //   meta: {
    //     icon: 'icon-yonghuguanli',
    //     title: '用户管理'
    //   },
    //   component: () => import('@/views/system/UserManagement'),
    // },
    {
      path: '/interiorUserManagement',
      name: 'interiorUserManagement',
      meta: {
        icon: 'icon-yonghuguanli',
        title: '用户管理'
      },
      component: () => import('@/views/system/interiorUserManagement'),
    }, {
      path: '/CompanyManagement',
      name: 'CompanyManagement',
      meta: {
        icon: 'icon-gongsi',
        title: '公司管理'
      },
      component: () => import('@/views/system/CompanyManagement'),
    }
    // {
    //   path: '/WaybillManagement',
    //   name: 'WaybillManagement',
    //   meta: {
    //     icon: 'icon-yundanguanli',
    //     title: '运单管理'
    //   },
    //   component: () => import('@/views/system/WaybillManagement'),
    // }
  ]
}
/**
 * 动态生成菜单
 * @param arrType
 * @returns {Promise<Router>}
 */
export const generatorDynamicRouter = arrType => {
  return new Promise((resolve, reject) => {
    const routers = []
    // if (arrType.userType == "sys") {
    //   if (arrType.deptId === 0) {
    //     routers.push(notFoundRouter)
    //     routers.push(companyRouter)
    //   } else {
    //     function deleteObjectById(arr, name) {
    //       return arr.filter(obj => obj.name !== name);
    //     }
    //     rootRouter.children = deleteObjectById(rootRouter.children, 'CompanyManagement')
    //     routers.push(notFoundRouter)
    //     routers.push(rootRouter)
    //     if (arrType.type == 1) {
    //       rootRouter.children = deleteObjectById(rootRouter.children, 'UserManagement')
    //       rootRouter.children.splice(1, 0, userRouter)
    //     } else {
    //       rootRouter.children = deleteObjectById(rootRouter.children, 'UserManagement')
    //     }
    //   }
    // } else {
    //   routers.push(notFoundRouter)
    //   routers.push(clientRouter)
    // }
    routers.push(notFoundRouter)
    if (arrType.userType == "sys") {
      if (arrType.deptId === 0) {
        routers.push(companyRouter)
      } else {
        if (arrType.dept.iceRaftManage) {
          routers.push(iceRouter)
        } else {
          if (arrType.type == 1) {
            routers.push(intendantRouter)
          } else {
            routers.push(deliverymanRouter)
          }
        }
      }
    }
    // console.log(routers, 243)
    resolve(routers)
  })
}
