// 动态路由
const routers = [
  // 服务大厅
  {
    path: '/service',
    name: 'service',
    meta: {
      icon: 'ios-cart',
      title: 'service_hall'
    },
    component: ()=>import('@/components/main'),
    children: [
      {
        path: 'set-meal',
        name: 'setMeal',
        meta: {
          icon: 'ios-git-compare',
          title: 'setmeallist_1'
        },
        component: () => import('@/view/service/set-meal/interlayer'),
        children: [
          {
            path: 'list',
            name: 'setMealList',
            meta: {
              icon: 'ios-reorder',
              title: 'api_meal_list'
            },
            component: () => import('@/view/service/set-meal/list')
          },
          {
            path: 'add',
            name: 'setMealAdd',
            meta: {
              icon: 'ios-add-circle-outline',
              title: 'add_meal'
            },
            component: () => import('@/view/service/set-meal/add')
          }
        ],
      },
      {
        path: 'order-manage',
        name: 'orderManage',
        meta: {
          icon: 'ios-reorder',
          title: 'order_manage'
        },
        component: () => import('@/view/service/order-manage')
      },
      {
        path: 'set-meal-manage',
        name: 'setMealManage',
        meta: {
          icon: 'ios-options-outline',
          title: 'meal_manage'
        },
        component: () => import('@/view/service/set-meal-manage')
      },
      {
        path: 'order',
        name: 'orderList',
        meta: {
          icon: 'ios-build-outline',
          title: 'pay_config'
        },
        component: () => import('@/view/service/config')
      }
    ]
  },
  // 账号管理
  {
    path: '/user',
    name: 'user',
    meta: {
      icon: 'md-person',
      title: 'account_manangement'
    },
    component: () => import('@/components/main'),
    children: [
      {
        path: 'list',
        name: 'userList',
        meta: {
          icon: 'ios-people',
          title: 'account_list'
        },
        component: () => import('@/view/user/list')
      },
      {
        path: 'add',
        name: 'addUser',
        meta: {
          icon: 'md-person-add',
          title: 'add_account'
        },
        component: () => import('@/view/user/add')
      },
      {
        path: 'look-over',
        name: 'lookOverUser',
        meta: {
          hideInMenu: true,
          icon: 'md-person-add',
          title: 'account_info'
        },
        component: () => import('@/view/user/look-over')
      },
      {
        path: 'compile',
        name: 'compileUser',
        meta: {
          hideInMenu: true,
          icon: 'md-person-add',
          title: 'account_edit'
        },
        component: () => import('@/view/user/compile')
      }
    ]
  },
  // 应用管理
  {
    path: '/application',
    name: 'application',
    meta: {
      icon: 'md-apps',
      title: 'app_management'
    },
    component: () => import('@/components/main'),
    children: [
      {
        path: 'list',
        name: 'applicationList',
        meta: {
          icon: 'ios-albums-outline',
          title: 'app_management'
        },
        component: () => import('@/view/application/list')
      },
      {
        path: 'add',
        name: 'addApplication',
        meta: {
          icon: 'ios-add-circle-outline',
          title: 'create_new_app'
        },
        component: () => import('@/view/application/add')
      },
      {
        path: 'update',
        name: 'appUpdate',
        meta: {
          hideInMenu: true,
          icon: 'ios-albums-outline',
          title: 'app_modify'
        },
        component: () => import('@/view/application/update')
      }
    ]
  },
  // 接口管理
  {
    path: '/techzones',
    name: 'techzones',
    meta: {
      icon: 'ios-git-network',
      title: 'api_management'
    },
    component: () => import('@/components/main'),
    children: [
      {
        path: 'techzones',
        name: 'portAuthority',
        meta: {
          icon: 'ios-unlock',
          title: 'api_permissions'
        },
        component: () => import('@/view/techzones/apis-mangement/interlayer'),
        children: [
          // 接口权限 新增
          // 接口管理
          /* {
            path: '/apis',
            name: 'apis',
            meta: {
              icon: 'ios-code',
              title: '接口管理(new)'
            },
            component: () => import('@/components/main'),
            children: [

            ]
          } */
          {
            path: 'assignment',
            name: 'assignment',
            meta: {
              icon: 'ios-unlock',
              title: 'api_assignment'
            },
            component: () => import('@/view/techzones/apis-mangement/assignment')
          },
          {
            path: 'assignmentList',
            name: 'assignmentList',
            meta: {
              icon: 'ios-eye',
              title: 'api_permissions_skim'
            },
            component: () => import('@/view/techzones/apis-mangement/assignmentList')
          },
          {
            path: 'assignmentRules',
            name: 'assignmentRules',
            meta: {
              icon: 'ios-cog-outline',
              title: 'api_rules_settings'
            },
            component: () => import('@/view/techzones/apis-mangement/assignment-rules')
          },
          {
            path: 'apisList',
            name: 'apisList',
            meta: {
              icon: 'ios-menu-outline',
              title: 'api_service_list'
            },
            component: () => import('@/view/techzones/apis-mangement/apis-list')
          }
        ]
      },
      {
        path: 'design',
        name: 'design',
        meta: {
          icon: 'ios-color-wand-outline',
          title: 'visual_api_design'
        },
        component: () => import('@/view/techzones/design')
      },
      {
        path: 'techzones',
        name: 'apitest',
        meta: {
          icon: 'ios-bug',
          title: 'test_api'
        },
        component: () => import('@/view/techzones/apitest/interlayer'),
        children: [
          {
            path: 'test',
            name: 'apitestTest',
            meta: {
              icon: 'md-bulb',
              title: 'test_api'
            },
            component: () => import('@/view/techzones/apitest/test')
          },
          {
            path: 'add',
            name: 'apitestAdd',
            meta: {
              icon: 'ios-add-circle-outline',
              title: 'add_new_example'
            },
            component: () => import('@/view/techzones/apitest/add')
          },
          {
            path: 'compile',
            name: 'apitestCompile',
            meta: {
              hideInMenu: true,
              icon: 'ios-create-outline',
              title: 'example_edition'
            },
            component: () => import('@/view/techzones/apitest/compile')
          },
          {
            path: 'look',
            name: 'apitestLook',
            meta: {
              hideInMenu: true,
              icon: 'ios-code-working',
              title: 'check_example'
            },
            component: () => import('@/view/techzones/apitest/look')
          },
          {
            path: 'config',
            name: 'apitestConfig',
            meta: {
              icon: 'md-cog',
              title: 'global_token_setting'
            },
            component: () => import('@/view/techzones/apitest/config')
          }
        ]
      }
    ]
  },
  // API USB DEMO
  {
    path: '/api-usb-workorder',
    name: 'apiUsbWorkOrder',
    // redirect: 'api-usb-demo/demo',
    meta: {
      icon: 'md-reorder',
      title: 'workorderlist18'
    },
    component: () => import('@/components/main'),
    children: [
      {
        path: 'list',
        name: 'apiUsbWorkOrderList',
        meta: {
          icon: 'ios-paper-outline',
          title: 'workorderlist1'
        },
        component: () => import('@/view/api-usb-workorder/list')
      },
      {
        path: 'info',
        name: 'apiUsbWorkOrderInfo',
        meta: {
          icon: 'md-flower',
          title: 'workorderinfo4',
          hideInMenu: true
        },
        component: () => import('@/view/api-usb-workorder/info')

      }
    ]
  },
  // 素材库
  {
    path: '/pictures',
    name: 'pictures',
    meta: {
      icon: 'md-images',
      title: 'material_library'
    },
    component: () => import('@/components/main'),
    children: [
      {
        path: 'assets_manage',
        name: 'assets_manage',
        meta: {
          icon: 'ios-image-outline',
          title: 'docunments'
        },
        component: () => import('@/view/assets-lib/assets-manage/index.vue')

      },
      {
        path: 'assets_upload',
        name: 'assets_upload',
        meta: {
          icon: 'ios-cloud-upload-outline',
          title: 'docunments_upload'
        },
        component: () => import('@/view/assets-lib/assets-upload/index.vue')
      }
    ]
  },
  // 个人账号信息管理
  {
    path: '/account',
    name: 'account',
    component: () => import('@/components/main'),
    meta: {
      hideInMenu: true
    },
    children: [
      {
        path: 'accountInfo',
        name: 'accountInfo',
        meta: {
          icon: 'md-flower',
          title: 'personal_info'
        },
        component: () => import('@/view/account/accountInfo.vue')
      },
      {
        path: 'loginRecord',
        name: 'loginRecord',
        meta: {
          icon: 'md-flower',
          title: 'rencently_sign_in'
        },
        component: () => import('@/view/account/loginRecord.vue')
      },
      {
        path: 'resetPassword',
        name: 'resetPassword',
        meta: {
          icon: 'md-flower',
          title: 'pwd_alter'
        },
        component: () => import('@/view/account/resetPwd.vue')
      },
      {
        path: 'accountSettings',
        name: 'accountSettings',
        meta: {
          icon: 'md-flower',
          title: 'modify_personal_info'
        },
        component: () => import('@/view/account/accountSettings.vue')
      }
    ]
  },
  // 配置管理
  {
    path: '/configuration',
    name: 'configuration',
    meta: {
      icon: 'ios-build-outline',
      title: 'config_manage'
    },
    component: () => import('@/components/main'),
    children: [
      {
        path: 'list',
        name: 'configList',
        meta: {
          icon: 'ios-build-outline',
          title: 'config_manage'
        },
        component: () => import('@/view/configuration/list')
      },
      {
        path: 'add',
        name: 'addmanagement',
        meta: {
          icon: 'md-add',
          title: 'add_config'
        },
        component: () => import('@/view/configuration/add')
      },
      {
        path: 'edit',
        name: 'editmanagement',
        meta: {
          hideInMenu: true,
          icon: 'md-add',
          title: 'alter_config'
        },
        component: () => import('@/view/configuration/edit')
      }
    ]
  },
  // 计划任务
  {
    path: '/scheduledtask',
    name: 'scheduledtask',
    meta: {
      icon: 'ios-timer-outline',
      title: 'scheduled_tasks'
    },
    component: () => import('@/components/main'),
    children: [
      {
        path: 'list',
        name: 'scheduledtasklist',
        meta: {
          icon: 'ios-timer-outline',
          title: 'task_list'
        },
        component: () => import('@/view/scheduledtask/list')
      },
      {
        path: 'add',
        name: 'addscheduledtask',
        meta: {
          icon: 'md-add',
          title: 'add_task'
        },
        component: () => import('@/view/scheduledtask/add')
      },
      {
        path: 'edit',
        name: 'editscheduledtask',
        meta: {
          hideInMenu: true,
          icon: 'md-add',
          title: 'edit_task'
        },
        component: () => import('@/view/scheduledtask/edit')
      }
      // ,
      // {
      //   path: '/database/statis',
      //   name: 'databaseStat',
      //   meta: {
      //     icon: 'ios-pulse-outline',
      //     title: 'database_status'
      //   },
      //   component: () => import('@/view/database/statis')
      // }
    ]
  },
  // 数据库
  {
    path: '/database',
    name: 'database',
    meta: {
      icon: 'ios-code-working',
      title: 'databse_management'
    },
    component: () => import('@/components/main'),
    children: [
      {
        path: 'statis',
        name: 'databaseStat',
        meta: {
          icon: 'ios-pulse-outline',
          title: 'database_status'
        },
        component: () => import('@/view/database/statis')
      },
      {
        path: 'process',
        name: 'databaseProcess',
        meta: {
          icon: 'ios-timer-outline',
          title: 'database_realtime_process'
        },
        component: () => import('@/view/database/process')
      }
    ]
  },
  // 统计
  {
    path: '/stats',
    name: 'stats',
    meta: {
      icon: 'ios-stats',
      title: 'statistics'
    },
    component: () => import('@/components/main'),
    children: [
      {
        path: 'port_stats',
        name: 'port_stats',
        meta: {
          icon: 'ios-unlock',
          title: 'statistics_api'
        },
        component: () => import('@/view/stats/port-stats/index.vue')
      },
      {
        path: 'app_stats',
        name: 'app_stats',
        meta: {
          icon: 'ios-analytics-outline',
          title: 'statistics_app'
        },
        component: () => import('@/view/stats/app-stats/index.vue')
      },
      {
        path: 'register_stats',
        name: 'register_stats',
        meta: {
          icon: 'ios-analytics-outline',
          title: 'statistics_register'
        },
        component: () => import('@/view/stats/register-stats/index.vue')
      },
      {
        path: 'login_stats',
        name: 'login_stats',
        meta: {
          icon: 'ios-analytics-outline',
          title: 'statistics_login'
        },
        component: () => import('@/view/stats/login-stats/index.vue')
      },
      {
        path: 'accessLog',
        name: 'accessLog',
        meta: {
          icon: 'ios-cog-outline',
          title: 'access_log'
        },
        component: () => import('@/view/techzones/accessLog')
      }
    ]
  }
]

// 权限分配页面
export const permission_page =
{
  path: '/permissions',
  name: 'route_permissions',
  meta: {
    icon: 'ios-stats',
    title: 'route_permissions'
  },
  component: () => import('@/components/main'),
  children: [
    {
      path: 'admin-assign',
      name: 'admin_permissions_assign',
      meta: {
        icon: 'ios-unlock',
        title: 'admin_assign'
      },
      component: () => import('@/view/permission/admin.vue')
    },
    {
      path: 'platform-assign',
      name: 'paltform_permissions_assign',
      meta: {
        icon: 'ios-analytics-outline',
        title: 'platform_assign'
      },
      component: () => import('@/view/permission/platform.vue')
    }
  ]
}

// 统一转换为绝对路由
const resolvePath = (...paths) => {
  let i = paths.length
  // 反向查找 / 开头的路径
  while (--i) {
    if (/^\//.test(paths[i])) break
  }
  return paths.slice(i)
    .join('/') // 加入 '/'
    .replace('//', '/') // 替换可能存在的 '//'
}
const restructure = (routes = [], base = '/') => {
  return routes.map(route => {
    let { path, children = [] } = route
    path = resolvePath(base, path)
    if (route.children && children.length > 0) {
      route.children = restructure(children, path)
    }
    return {
      ...route,
      path
    }
  })
}

// 转换为绝对路由
export const asynRouters = restructure(routers, '/')

const [...new_routes] = routers
export const asynRouters_copy = restructure(new_routes.concat(permission_page), '/')

// 此部分代码用于超管号一键添加所有权限
// const [...all_routes] = routers
// const path_arr = []
// const restructure_only_path = (routes = [], base = '/') => {
//   routes.map(route => {
//     const item = {}
//     console.log(route)
//     item.path = resolvePath(base, route.path)
//     item.title = route.meta.title
//     path_arr.push(item)
//     if (route.children && route.children.length > 0) {
//       route.children = restructure_only_path(route.children, route.path)
//     }
//   })
// }
// restructure_only_path(all_routes, '/')
// console.log('path_arr', path_arr)
// export const all_path = path_arr
