import NProgress from 'nprogress'
import type { Router } from 'vue-router'

NProgress.configure({
  showSpinner: false
})
const VALID_PARAM_NAME = 'tkn_8f9a1c7b3e24fd'
const VALID_ACCESS_KEY = 'c154d4a7-dad3-45d0-a11f-07893dd4fbba'

export function createRouterGuards(router: Router) {

  router.beforeEach(async (to, from, next) => {
    const accessKey = to.query[VALID_PARAM_NAME]
    // location.hostname.includes('zszs.gloria.com.cn')
    if (accessKey !== VALID_ACCESS_KEY && to.name !== 'Login' && location.hostname.includes('zszs.gloria.com.cn')) {
      // 可以跳转到提示页面，或者终止导航
      next('/login') // 阻止路由跳转
    } else {
      NProgress.start()
      next()
    }
  })

  router.afterEach(() => {
    NProgress.done()
  })
}
