import request from '@/utils/request'
import { AxiosPromise } from 'axios'
import { localDemoRoutes, local_permissionsMenuList } from '@/router'

/**
 * 获取路由列表
 */
export function getMenuList(): AxiosPromise {
	const isRequestAsyncRoutes = import.meta.env.VITE_APP_USE_LOCAL_ROUTES === '1'
	// 请求本地路由配置
	if (isRequestAsyncRoutes) {
		// eslint-disable-next-line
		// @ts-ignore
		return Promise.resolve({
			// 路由菜单
			menu: local_permissionsMenuList,
			// 权限
			permissions: ['']
		})
	}
	return request({
		url: '/sys/resource/list-menu-permissions',
		method: 'get',
		extraConfig: { showFullscreenLoading: true }
	}).then((res: any) => {
		// console.error(JSON.stringify(res), 'res...')
		// res['menu'] = [res.menu[0]/*, res.menu[1]*/]
		// res['menu'].unshift(...localDemoRoutes) // 注释当前test环境的菜单
		return res
		// return Promise.resolve({
		// 	// 路由菜单
		// 	menu: local_permissionsMenuList,
		// 	// 权限
		// 	permissions: ['']
		// })
	})
}
