import { createRouter, createWebHashHistory, 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: "/process",
    children: [
      {
        path: "process",
        component: () => import("@/views/process/main.vue"),
        name: "ProcessMain",
        meta: {
          title: "process",
          icon: "homepage",
        },
      },
      {
        path: "pro-steps",
        redirect: "/pro-steps/wuliaocaiji",
        component: () => import("@/views/pro-steps/index.vue"),
        name: "ProSteps",
        meta: {
          title: "pro-steps",
          icon: "homepage",
          keepAlive: true,
          back: true,
        },
        children: [
          {
            path: "dianjian",
            component: () =>
              import("@/views/pro-steps/components/dianjian.vue"),
            name: "Dianjian",
            meta: {
              back: true,
            },
          },
          {
            path: "duomeiticaiji",
            component: () =>
              import("@/views/pro-steps/components/duomeiticaiji.vue"),
            name: "Duomeiticaiji",
            meta: {
              back: true,
            },
          },
          {
            path: "esop",
            component: () => import("@/views/pro-steps/components/ESOP.vue"),
            name: "Esop",
            meta: {
              back: true,
            },
          },
          {
            path: "jingu",
            component: () => import("@/views/pro-steps/components/jingu.vue"),
            name: "Jingu",
            meta: {
              back: true,
            },
          },
          {
            path: "mingpaibangding",
            component: () =>
              import("@/views/pro-steps/components/mingpaibangding.vue"),
            name: "Mingpaibangding",
            meta: {
              back: true,
            },
          },
          {
            path: "jiluxiang",
            component: () =>
              import("@/views/pro-steps/components/jiluxiang.vue"),
            name: "Jiluxiang",
            meta: {
              back: true,
              keepAlive: true,
            },
          },
          {
            path: "shebeijilu",
            component: () =>
              import("@/views/pro-steps/components/shebeijilu.vue"),
            name: "Shebeijilu",
            meta: {
              back: true,
            },
          },
          {
            path: "tiaoshipipei",
            component: () =>
              import("@/views/pro-steps/components/tiaoshipipei.vue"),
            name: "Tiaoshipipei",
            meta: {
              back: true,
            },
          },
          {
            path: "wuliaocaiji",
            component: () =>
              import("@/views/pro-steps/components/wuliaocaiji.vue"),
            name: "Wuliaocaiji",
            meta: {
              back: true,
              keepAlive: true,
            },
          },
        ],
      },
    ],
  },

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

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

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

export default router;
