import { createRouter, createWebHashHistory } from 'vue-router';
import type { RouteRecordRaw } from 'vue-router';
import type { App } from 'vue';
import { Layout } from '@/utils/routerHelper';
import { useI18n } from '@/hooks/web/useI18n';

const { t } = useI18n();

export const constantRouterMap: AppRouteRecordRaw[] = [
  {
    path: 'checkversion',
    component: () => import('@/views/csck/CsckCheckVesrion/CsckCheckVesrion.vue'),
    name: 'Checkversion',
    menuId: 'checkversion',
    meta: {
      title: '校验版本管理',
    },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  strict: true,
  routes: constantRouterMap as RouteRecordRaw[],
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

export const resetRouter = (): void => {
  const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root'];
  router.getRoutes().forEach(route => {
    const { name } = route;
    if (name && !resetWhiteNameList.includes(name as string)) {
      router.hasRoute(name) && router.removeRoute(name);
    }
  });
};

export const setupRouter = (app: App<Element>) => {
  app.use(router);
};

export default router;
