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

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

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

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

  {
    path: "/",
    component: Layout,
    redirect: "/model",
    children: [
      {
        path: "model",
        component: () => import("@/views/mangage/model.vue"),
        name: "model",
        meta: {
          title: "model",
          icon: "homepage",
          affix: true,
          name: "modelMangage.title",
        },
      },
    ],
  },

  {
    path: "/",
    component: Layout,
    redirect: "/keyList",
    children: [
      {
        path: "keyList",
        component: () => import("@/views/keys/keyList.vue"),
        name: "keyList",
        meta: {
          title: "keyList",
          icon: "homepage",
          affix: true,
          name: "keyMangage.list",
        },
      },
    ],
  },
  {
    path: "/",
    component: Layout,
    redirect: "/keyCheck",
    children: [
      {
        path: "keyCheck",
        component: () => import("@/views/keys/keyCheck.vue"),
        name: "keyCheck",
        meta: {
          title: "keyCheck",
          icon: "homepage",
          affix: true,
          name: "keyMangage.title",
        },
      },
    ],
  },
  {
    path: "/",
    component: Layout,
    redirect: "/businessList",
    children: [
      {
        path: "businessList",
        component: () => import("@/views/business/businessList.vue"),
        name: "businessList",
        meta: {
          title: "businessList",
          icon: "homepage",
          affix: true,
          name: "keyMangage.list",
        },
      },
    ],
  },
  {
    path: "/",
    component: Layout,
    redirect: "/businessCheck",
    children: [
      {
        path: "businessCheck",
        component: () => import("@/views/apiManage/businessCheck.vue"),
        name: "businessCheck",
        meta: {
          title: "businessCheck",
          icon: "homepage",
          affix: true,
          name: "keyMangage.title",
        },
      },
    ],
  },
  // 系统设置路由
  {
    path: "/",
    component: Layout,
    redirect: "/userList",
    children: [
      {
        path: "userList",
        component: () => import("@/views/dict/index.vue"),
        name: "userList",
        meta: {
          title: "userList",
          icon: "homepage",
          affix: true,
          name: "userListMangage.title",
        },
      },
    ],
  },
  {
    path: "/",
    component: Layout,
    redirect: "/ruleList",
    children: [
      {
        path: "ruleList",
        component: () => import("@/views/mangage/ruleList.vue"),
        name: "ruleList",
        meta: {
          title: "ruleList",
          icon: "homepage",
          affix: true,
          name: "ruleListMangage.title",
        },
      },
    ],
  },
  {
    path: "/",
    component: Layout,
    redirect: "/home",
    children: [
      {
        path: "/home",
        component: () => import("@/views/home/index.vue"),
        name: "home",
        meta: {
          title: "home",
          icon: "home",
          affix: true,
          name: "ruleListMangage.title",
        },
      },
      {
        path: "/apiManage",
        component: () => import("@/views/apiManage/index.vue"),
        name: "apiManage",
        meta: {
          title: "apiManage",
          icon: "homepage",
          affix: true,
          name: "ruleListMangage.title",
        },
      },
      {
        path: "/privatization",
        component: () => import("@/views/privatization/index.vue"),
        name: "privatization",
        meta: {
          title: "privatization",
          icon: "homepage",
          affix: true,
          name: "ruleListMangage.title",
        },
      },
      {
        path: "/template",
        component: () => import("@/views/template/index.vue"),
        name: "template",
        meta: {
          title: "template",
          icon: "homepage",
          affix: true,
          name: "ruleListMangage.title",
        },
      },
      {
        path: "/secretKey",
        component: () => import("@/views/secretKey/index.vue"),
        name: "secretKey",
        meta: {
          title: "secretKey",
          icon: "homepage",
          affix: true,
          name: "ruleListMangage.title",
        },
      },
      {
        path: "/video",
        component: () => import("@/views/video/index.vue"),
        name: "video",
        meta: {
          title: "video",
          icon: "homepage",
          affix: true,
          name: "ruleListMangage.title",
        },
      },
      {
        path: "/userManage",
        component: () => import("@/views/userManage/userList.vue"),
        name: "userManage",
        meta: {
          title: "userManage",
          icon: "homepage",
          affix: true,
          name: "ruleListMangage.title",
        },
      },
      {
        path: "/userMouldList",
        component: () => import("@/views/userManage/userMouldList.vue"),
        name: "userMouldList",
        meta: {
          title: "userMouldList",
          icon: "homepage",
          affix: true,
          name: "ruleListMangage.title",
        },
      },
      {
        path: "/userVoiceList",
        component: () => import("@/views/userManage/userVoiceList.vue"),
        name: "userVoiceList",
        meta: {
          title: "userVoiceList",
          icon: "homepage",
          affix: true,
          name: "ruleListMangage.title",
        },
      },

      {
        path: "/rechargeList",
        component: () => import("@/views/userManage/rechargeList.vue"),
        name: "rechargeList",
        meta: {
          title: "rechargeList",
          icon: "homepage",
          affix: true,
          name: "ruleListMangage.title",
        },
      },
      {
        path: "/videoList",
        component: () => import("@/views/userManage/videoList.vue"),
        name: "videoList",
        meta: {
          title: "videoList",
          icon: "homepage",
          affix: true,
          name: "ruleListMangage.title",
        },
      },
    ],
  }
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  // 2023-5-23 添加平滑滚动 YWQ
  scrollBehavior: () => ({ behavior: "smooth", left: 0, top: 0 }),
});

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

export default router;
