import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },

  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/main",
    children: [
      {
        path: "main",
        component: () => import("@/views/main/main.vue"),
        name: "main",

        meta: {
          title: "综合管理平台",
          icon: "homepage",
        },
      },
      {
        path: "/users",
        component: () => import("@/views/sets/users.vue"),
        name: "users",
        meta: { hidden: true, back: true, title: "用户权限管理" },
      },
      {
        path: "/user/changePassword",
        component: () => import("@/views/sets/changePassword.vue"),
        name: "changePassword",
        meta: { hidden: true, back: true, title: "修改用户密码" },
      },
      {
        path: "/messageOrg",
        component: () => import("@/views/sets/messageOrg.vue"),
        name: "messageOrg",
        meta: { hidden: true, back: true, title: "消息组织管理" },
      },
      {
        path: "/roles",
        component: () => import("@/views/sets/roles.vue"),
        name: "Roles",
        meta: { hidden: true, back: true, title: "角色管理" },
      },
      {
        path: "/files",
        component: () => import("@/views/sets/files.vue"),
        name: "Files",
        meta: {hidden: true, back: true, title: "文件管理"},
      },
      {
        path: "/messagesList/:type",
        component: () => import("@/views/messages/index.vue"),
        name: "messagesList",
        meta: { hidden: true, back: true, title: "信息中心" },
      },
    ],
  },
  {
    path: "/totalScreen",
    component: () => import("@/views/big-screens/TotalScreen.vue"),
    name: "totalScreen",
    meta: { hidden: true },
  },
  {
    path: "/mainScreen",
    component: () => import("@/views/screens/mainScreen.vue"),
    name: "mainScreen",
    meta: { hidden: true },
  },
  {
    path: "/qualityScreen",
    component: () => import("@/views/screens/qualityScreen.vue"),
    name: "qualityScreen",
    meta: { hidden: true },
  },
  {
    path: "/workScreen",
    component: () => import("@/views/screens/workScreen.vue"),
    name: "workScreen",
    meta: { hidden: true },
  },
  {
    path: "/deviceScreen",
    component: () => import("@/views/screens/deviceScreen.vue"),
    name: "deviceScreen",
    meta: { hidden: true },
  },

  {
    path: "/:pathMatch(.*)*", // 必备
    component: () => import("@/views/error-page/404.vue"),
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router;
