import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
  type RouteRecordRaw
} from 'vue-router';

// import { authGuard } from '@/router/routerGuard';

export const constantRoutes: Readonly<RouteRecordRaw[]> = [
  {
    path: '/',
    // redirect: '/home/overall/overview'
    redirect: '/home/overall/extinguishing/edit'
  },
  {
    name: 'home',
    path: '/home',
    component: () => import('@/layout/index.vue'),
    children: [
      {
        path: '/home/overall',
        name: 'homeOverall',
        component: () => import('@/layout/themeLayout/index.vue'),
        children: [
          {
            path: '/home/overall/overview',
            name: 'homeOverallOverview',
            // component: () => import('@/views/edit/index.vue'),
            component: () => import('@/views/preview/index.vue'),
            meta: { title: '全站总览' }
          },
          {
            path: '/home/overall/extinguishing',
            name: 'extinguishing',
            meta: { title: '消防系统' },
            children: [
              {
                path: '/home/overall/extinguishing/view',
                name: 'homeOverallExtinguishingView',
                component: () => import('@/views/preview/index.vue'),
                meta: { title: '消防view' }
              },
              {
                path: '/home/overall/extinguishing/edit',
                name: 'homeOverallExtinguishingEdit',
                component: () => import('@/views/edit/index.vue'),
                meta: { title: '消防edit' }
              }
            ]
          },
          {
            path: '/home/overall/security',
            name: 'security',
            meta: { title: '安全防范' },
            children: [
              {
                path: '/home/overall/security/test',
                name: 'securityEditTest',
                component: () => import('../views/edit/indexTest.vue'),
                meta: { title: '安全防范-test' }
              },
              {
                path: '/home/overall/security/test01',
                name: 'securityEditTest01',
                component: () => import('../views/edit/indexTest.vue'),
                meta: { title: '安全防范-test01' }
              }
            ]
          },
          {
            path: '/home/overall/monitoring',
            name: 'monitoring',
            component: () => import('../views/edit/index.vue'),
            meta: { title: '在线监测' },
            children: [
              {
                path: '/home/overall/monitoring/test',
                name: 'monitoringEditTest',
                component: () => import('../views/edit/index.vue'),
                meta: { title: '在线监测-test' }
              }
            ]
          },
          {
            path: '/home/overall/rainage',
            name: 'drainage',
            component: () => import('../views/edit/index.vue'),
            meta: { title: '给排水系统' },
            children: [
              {
                path: '/home/overall/rainage/test',
                name: 'rainageEditTest',
                component: () => import('../views/edit/index.vue'),
                meta: { title: '给排水系统-test' }
              }
            ]
          },
          {
            path: '/home/overall/monitoring',
            name: 'monitoring',
            component: () => import('../views/edit/index.vue'),
            meta: { title: '环境监控' },
            children: [
              {
                path: '/home/overall/monitoring/test',
                name: 'monitoringEditTest',
                component: () => import('../views/edit/index.vue'),
                meta: { title: '环境监控-test' }
              }
            ]
          },
          {
            path: '/home/overall/lighting',
            name: 'lighting',
            component: () => import('../views/edit/index.vue'),
            meta: { title: '照明控制' },
            children: [
              {
                path: '/home/overall/lighting/test',
                name: 'lightingEditTest',
                component: () => import('../views/edit/index.vue'),
                meta: { title: '照明控制-test' }
              }
            ]
          },
          {
            path: '/home/overall/intelligent',
            name: 'intelligent',
            component: () => import('../views/edit/index.vue'),
            meta: { title: '智能联动' },
            children: [
              {
                path: '/home/overall/intelligent/test',
                name: 'intelligentEditTest',
                component: () => import('../views/edit/index.vue'),
                meta: { title: '智能联动-test' }
              }
            ]
          },
          {
            path: '/home/overall/lock',
            name: 'lock',
            component: () => import('../views/edit/index.vue'),
            meta: { title: '智能锁控' },
            children: [
              {
                path: '/home/overall/lock/test',
                name: 'lockEditTest',
                component: () => import('../views/edit/index.vue'),
                meta: { title: '智能锁控-test' }
              }
            ]
          },
          {
            path: '/home/overall/config',
            name: 'config',
            component: () => import('../views/edit/index.vue'),
            meta: { title: '系统配置' },
            children: [
              {
                path: '/home/overall/config/test',
                name: 'configTest',
                component: () => import('../views/edit/index.vue'),
                meta: { title: '系统配置-test' }
              }
            ]
          },
          {
            path: '/home/overall/exploitEdit',
            name: 'exploitEdit',
            meta: { title: '开发Edit' },
            children: [
              {
                path: '/home/overall/exploitEdit/test',
                name: 'exploitEditTest',
                component: () => import('@/views/edit/index.vue'),
                meta: { title: 'Edit' }
              },
              {
                path: '/home/overall/exploitEdit/test',
                name: 'exploitEditTest01',
                component: () => import('../views/edit/indexTest.vue'),
                meta: { title: 'Edit01' }
              }
            ]
          }
        ]
      }
    ]
  },
  // 测试页面START
  {
    name: 'edit',
    path: '/edit',
    component: () => import('../views/edit/index.vue')
  },
  {
    name: 'demo',
    path: '/demo',
    component: () => import('../views/demo/index.vue')
  },
  {
    name: 'preview',
    path: '/preview',
    component: () => import('../views/preview/index.vue')
  },
  {
    name: 'edit-load',
    path: '/edit-load',
    component: () => import('../views/demo/edit-load.vue')
  },
  {
    name: 'set-node-attr',
    path: '/set-node-attr',
    component: () => import('../views/demo/set-node-attr.vue')
  },
  {
    name: 'event-callback',
    path: '/event-callback',
    component: () => import('../views/demo/event-callback.vue')
  },
  {
    name: 'change-attr',
    path: '/change-attr',
    component: () => import('../views/demo/change-attr.vue')
  }
  // 测试页面EDN
];

const router = createRouter({
  history: createWebHashHistory(), // hash模式：createWebHashHistory，history模式：createWebHistory
  routes: constantRoutes
});

// 全局前置守卫 - 对所有路由生效
router.beforeEach((to, from, next) => {
  console.log('全局路由守卫触发：', to, from);
  next();
});

export default router;
