import { createRouter, createWebHistory } from 'vue-router';
import { accountGuard } from '@/router/guard/account.guard';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/login', name: 'login', component: () => import('@/pages/login.vue') },
    { path: '/screen', name: 'screen', component: () => import('@/pages/screen.page.vue'), meta: { scan: true } },
    { path: '/register', component: () => import('@/pages/register.page.vue'), meta: { title: '建档', scan: true } },
    { path: '/pulse', component: () => import('@/modules/pulse/pulse.page.vue'), meta: { title: '脉诊' } },
    { path: '/pulse/result', component: () => import('@/modules/pulse/pulse-result.page.vue'), meta: { title: '脉象分析报告' } },
    { path: '/camera', component: () => import('@/modules/camera/camera.page.vue'), meta: { title: '拍摄' } },
    { path: '/camera/result', component: () => import('@/modules/report/report-analyse.page.vue'), meta: { title: '舌面象分析报告' } },
    { path: '/questionnaire', component: () => import('@/modules/questionnaire/page.vue'), meta: { title: '问卷' } },
    { path: '/alcohol/result', component: () => import('@/modules/alcohol/alcohol.page.vue'), meta: { title: '黄酒建议' } },
    { path: '/report/analysis', redirect: '/camera/result' },
    { path: '/report/:id/scheme', component: () => import('@/modules/report/scheme.page.vue'), meta: { title: '调理方案', toggle: true } },
    { path: '/report/:id(\\w+)?', component: () => import('@/modules/report/report.page.vue'), meta: { title: '健康分析报告' } },
    { path: '/scheme/:id(\\w+)?', component: () => import('@/modules/report/scheme.page.vue'), meta: { title: '调理方案', toggle: false } },
    { path: '/crossing/:flow(\\w+)?', component: () => import('@/pages/crossing.page.vue') },
    {
      path: '/manage',
      children: [
        { path: 'system/role', component: () => import('@/modules/system/role.page.vue'), meta: { title: '角色管理' } },
        { path: 'system/user', component: () => import('@/modules/system/user.page.vue'), meta: { title: '用户管理' } },
        { path: 'system/logger', component: () => import('@/modules/system/logger.page.vue'), meta: { title: '日志管理' } },
      ],
    },
    { path: '/forbidden', name: 'forbidden', component: () => import('@/router/pages/forbidden.page.vue') },
    { path: '/', redirect: '/screen' },
  ],
});

router.beforeEach(accountGuard);

export default router;
export const flow_start = 'start';
export const flow_router = {
  'patient_file': '/register',
  'pulse_upload': '/pulse',
  'pulse_upload_result': '/pulse/result',
  'tongueface_upload': '/camera',
  'tongueface_analysis_result': '/camera/result',
  'tongueface_analysis': '/questionnaire',
  'alcohol_upload_result': '/alcohol/result',
  'health_analysis': '/report',
  'health_analysis_scheme': '/scheme',
  [flow_start]: '/screen',
} as const;

export function getRoutePath(key?: string) {
  key = key?.split('?')?.[0];
  return flow_router[key as keyof typeof flow_router];
}