
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: '/',
    component: Layout,
    redirect: '/dashboard/home',
    name: 'Root',
    meta: {
      hidden: true
    }
  },
  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard/home',
    name: 'Dashboard',
    menuId: 'Dashboard',
    meta: {
      title: '首页',
      icon: 'ant-design:home-outlined',
      hidden: true,
    },
    children: [
      {
        path: 'home',
        component: () => import('@/views/csck/CsckWorkFlow/CsckWorkFlow.vue'),
        name: 'Home',
        menuId: 'Home',
        meta: {
          title: '待办任务',
          affix: true,
          hidden: true,
        },
      },
    ],
  },
  {
    path: '/redirect',
    component: Layout,
    name: 'Redirect',
    children: [
      {
        path: '/redirect/:path(.*)',
        name: 'Redirect',
        component: () => import('@/views/Redirect/Redirect.vue'),
        meta: {},
      },
    ],
    meta: {
      hidden: true,
      noTagsView: true,
    },
  },
  {
    path: '/login',
    component: () => import('@/views/Login/Login.vue'),
    name: 'Login',
    meta: {
      hidden: true,
      title: t('router.login'),
      noTagsView: true,
    },
  },
  {
    path: '/thirdPlatLogin',
    component: () => import('@/views/Login/thirdPlatLogin.vue'),
    name: 'thirdPlatLogin',
    meta: {
      hidden: true
    },
  },
  {
    path: '/404',
    component: () => import('@/views/Error/404.vue'),
    name: 'NoFind',
    meta: {
      hidden: true,
      title: '404',
      noTagsView: true,
    },
  },

  {
    path: '/RepJob',
    component: () => import('@/views/job/RepJob/RepJob.vue'),
    name: 'RepJob',
    meta: {
      title: '作业配置',
      hidden:true
    },
  },
  {
    path: '/JobMonitor',
    component: () => import('@/views/job/RepTask/RepTask.vue'),
    name: 'JobMonitor',
    meta: {
      title: '任务监控',
      hidden:true
    },
  },  
  {
    path: '/RepScheduleJob',
    component: () => import('@/views/job/RepScheduleJob/RepScheduleJob.vue'),
    name: 'RepScheduleJob',
    meta: {
      title: '定时任务列表',
      hidden:true
    },
  }
];

export const asyncRouterMap: AppRouteRecordRaw[] = [];

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;
