import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import Layout from "@/layout/index.vue";

export const constantRoutes = [
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
          {
            path: '/redirect/:path(.*)',
            component: () => import('@/views/redirect/index.vue')
          }
        ]
    },
    {
        path: '/',
        redirect: '/login', // 这里做重定向
        hidden: true,
    },
    {
        path: "/login",
        component: () => import("@/views/login.vue"),
        meta: { title: "登录" },
        hidden: true,
    }, 
    {
        path: "/userManagement", 
        redirect: "/userManagement/UserManagementPage",
        component: Layout,  
        children: [
            {
                path: 'UserManagementPage',
                name: "UserManagement",
                component: () => import("@/views/userManagement/index.vue"),
                meta: { title: "用户管理", icon: "client", affix: true },
            }
        ]
    },
    {
        path: "/roleManagement", 
        redirect: "/roleManagement/RoleManagementPage",
        component: Layout,  
        children: [
            {
                path: 'RoleManagementPage',
                name: "RoleManagement",
                component: () => import("@/views/roleManagement/index.vue"),
                meta: { title: "角色管理", icon: "client", affix: true },
            }
        ]
    },
    {
        path: "/menuManagement", 
        redirect: "/menuManagement/MenuManagementPage",
        component: Layout,  
        children: [
            {
                path: 'MenuManagementPage',
                name: "MenuManagement",
                component: () => import("@/views/menuManagement/index.vue"),
                meta: { title: "菜单管理", icon: "client", affix: true },
            },
            
        ]
    },
    {
        path: "/roomManagement", 
        redirect: "/roomManagement/RoomManagementPage",
        component: Layout,  
        children: [
            {
                path: 'RoomManagementPage',
                name: "RoomManagement",
                component: () => import("@/views/roomManagement/index.vue"),
                meta: { title: "房间管理", icon: "client", affix: true },
            },
            
        ]
    },
    {
        path: "/interfaceManagement", 
        redirect: "/interfaceManagement/InterfaceManagementPage",
        component: Layout,  
        children: [
            {
                path: 'InterfaceManagementPage',
                name: "InterfaceManagement",
                component: () => import("@/views/interfaceManagement/index.vue"),
                meta: { title: "接口管理", icon: "client", affix: true },
            },
            
        ]
    }, 
    // {
    //     path: "/patrolMission", 
    //     redirect: "/patrolMission/PatrolMissionPage",
    //     component: Layout,  
    //     children: [
    //         {
    //             path: 'PatrolMissionPage',
    //             name: "PatrolMission",
    //             component: () => import("@/views/patrolMission/index.vue"),
    //             meta: { title: "设备知识库", icon: "client", affix: true },
    //         },
            
    //     ]
    // },
    {
        path: '/room-auth',
        component: Layout,
        hidden: true,
        children: [
          {
            path: 'room/:roomId(\\w+)',
            component: () => import('@/views/roomManagement/authRoom.vue'),
            name: 'AuthRoom',
            meta: { title: '参与者信息', activeMenu: '/roomManagement/RoomManagementPage', affix: true, icon: '' }
          }
        ]
      },
    {
        path: '/user-auth',
        component: Layout,
        hidden: true,
        children: [
          {
            path: 'role/:userId(\\w+)',
            component: () => import('@/views/userManagement/authRole.vue'),
            name: 'AuthRole',
            meta: { title: '分配角色', activeMenu: '/userManagement/UserManagementPage', affix: true, icon: '' }
          }
        ]
      },
    // {
    //     path: '/role-auth',
    //     component: Layout,
    //     hidden: true, 
    //     children: [
    //       {
    //         path: 'menu/:roleId(\\w+)',
    //         component: () => import('@/views/roleManagement/authMenu.vue'),
    //         name: 'AuthUser',
    //         meta: { title: '分配菜单',activeMenu: '/roleManagement/RoleManagementPage', affix: true , icon: '' }
    //       }
    //     ]
    // }, 
    // {
    //     path: "/system",
    //     redirect: "/system/menuManagement",
    //     component: Layout,
    //     meta: { title: "系统管理", icon: "system", affix: true },
    //     children: [
    //         {
    //             path: "menuManagement",
    //             name: "MenuManagement",
    //             component: () => import("@/views/menuManagement/index.vue"),
    //             meta: { title: "菜单管理", icon: "menu", affix: true },
    //         },
    //         {
    //             path: "userManagement", 
    //             name: "UserManagement",
    //             component: () => import("@/views/userManagement/index.vue"),
    //             meta: { title: "用户管理", icon: "user", affix: true },
    //         }
    //     ]
    // }, 
    // 错误页面路由
    {
        path: "/:pathMatch(.*)*",
        component: () => import("@/views/error/404.vue"),
        hidden: true,
    },
    {
        path: "/401",
        component: () => import("@/views/error/401.vue"),
        hidden: true,
        meta: { title: "401未授权" }
    },  
]

export const dynamicRoutes = [
    
]
const router = createRouter({
    // history: createWebHistory(import.meta.env.VITE_BASE_PATH),
    history: createWebHashHistory(import.meta.env.BASE_URL),
    routes: constantRoutes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition;
        } else {
            return { top: 0 };
        }
    },
});


export default router
