import { createRouter, createWebHistory, type Router } from 'vue-router';
import { titleGuard } from './guards';
import routeList from './routes';
import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'

let router: Router | null = null
export const createProjectRouter = (base = '') => {
  const __POWERED_BY_QIANKUN__ = qiankunWindow.__POWERED_BY_QIANKUN__ || window.proxy?.__POWERED_BY_QIANKUN__
  router = createRouter({
    history: createWebHistory(base || (__POWERED_BY_QIANKUN__ ? '/y-code-app/' : '')),
    routes: routeList,
  })

  // 全局前置守卫
  router.beforeEach(titleGuard)
  return router
}

export default router;
