import { open, close } from '/src/helpers/loading'

const getRouterComponent = (name: string) => async () => {
  const timer = setTimeout(() => {
    open()
  }, 300)
  let res: Promise<any> = Promise.resolve(null)
  try {
    res = await import(/* @vite-ignore */ `../src/pages/${name}/index.tsx`)
  } catch (error) {
    res = Promise.reject()
  }
  clearTimeout(timer)
  close()
  return res
}

export default [
  {
    path: '/',
    component: getRouterComponent('baseClass'),
  },
  {
    path: '/classify',
    component: getRouterComponent('classify')
  },
  {
    path: '/list/:id',
    component: getRouterComponent('list'),
    meta: {
      keepAlive: true
    }
  },
  { path: '/detail/:id', component: getRouterComponent('detail') },
  { path: '/evaluating/:id', component: getRouterComponent('detail') },
  { path: '/report', component: getRouterComponent('report') },
  { path: '/report/:id', component: getRouterComponent('report') },
  { path: '/render-test', component: getRouterComponent('render-test') },
  { path: '/vexflow-test', component: import('./vexflow-test')  },
  {
    path: '/:pathMatch(.*)*',
    component: getRouterComponent('notfund'),
    meta: {
      title: '404 Not Fund'
    }
  },
]
