import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import type { App } from 'vue';
// module routers
import { getModuleRoutes, getModuleViewComponents } from './constantRoutes';

const moduleRoutes = getModuleRoutes();
getModuleViewComponents();
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/dashboard',
	  meta: {hidden:true},
    component: () => import('@/layout/index.vue'),
    children: [
      {
        path: '',
        name: 'Dashboard',
        meta: { title: 'home', icon: 'home', hidden: true },
        component: () => import('@/views/dashboard/index.vue')
      }
    ]
  }
]
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  // @ts-ignore
  .concat(moduleRoutes);

// default routes, it will not change to menus
const defaultRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    name: '/',
    component: () => import('@/layout/index.vue'),
    redirect: '/dashboard',
    children: [
      {
        path: '/404',
        name: '404',
        meta: { title: '404' },
        component: () => import('@/components/404/index.vue')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    meta: { title: '登录' },
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/find',
    name: 'find',
    meta: { title: '找回密码' },
    component: () => import('@/views/login/find.vue')
  }
];

const routes = constantRoutes.concat(defaultRoutes);
const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // 路由滚动
  scrollBehavior(to, from, savedPosition) {
    return savedPosition || { top: 0, behavior: 'smooth' };
  }
});

export function bootstrapRouter(app: App) {
  app.use(router);
}

export default router;
