import Vue from "vue"
import VueRouter from "vue-router"
import Layout from "@/layouts"
import layout from "@/components/layout"
import EmptyLayout from "@/layouts/EmptyLayout"
Vue.use(VueRouter)

export const constantRoutes = [
  {
    path: "/home",
    name: "Home",
    // redirect: "/home",
    component: layout,
    children: [
      {
        path: "/home",
        component: () => import("@/views/Home/index"),
      },
      {
        path: "/allianceintroduction",
        component: () => import("@/views/Home/AllianceIntroduction/index"),
      },
      {
        path: "/casesharing",
        component: () => import("@/views/Home/CaseSharing/index"),
      },
      {
        path: "/scientificresearch",
        component: () => import("@/views/Home/ScientificResearch/index"),
      },
      {
        path: "/healthpopularization",
        component: () => import("@/views/Home/HealthPopularization/index"),
      },
    ],
  },
  // {
  //   path: "/login",
  //   component: () => import("@/views/login/index"),
  //   hidden: true,
  //   name: "login",
  // },
  {
    path: "/followupentry",
    component: Layout,
    children: [
      {
        path: "/followupentry",
        component: () => import("@/views/followupentry/index"),
        hidden: true,
        name: "followupEntry",
      },
    ],
  },
  {
    path: "/401",
    name: "401",
    component: () => import("@/views/401"),
    hidden: true,
  },
  {
    path: "/404",
    name: "404",
    component: () => import("@/views/404"),
    hidden: true,
  },
  {
    path: "/sso",
    name: "sso",
    component: () => import("@/views/sso"),
    hidden: true,
  },

  {
    path: "/test",
    component: Layout,
    children: [
      {
        path: "/test",
        name: "test",
        component: () => import("@/views/test"),
        hidden: true,
        meta: {
          noKeepAlive: true,
          title: "测试",
        },
      },
    ],
  },

  // {
  //   path: "/",
  //   component: Layout,
  //   redirect: "/index",
  //   children: [
  //     {
  //       path: "/index",
  //       name: "index",
  //       component: () => import("@/views/index/index"),
  //       meta: {
  //         title: "主页",
  //         icon: "home",
  //         affix: true,
  //         noKeepAlive: true,
  //       },
  //     },
  //   ],
  // },

  {
    path: "/personal",
    component: Layout,
    redirect: "noRedirect",
    meta: {
      title: "个人中心",
      // icon: "user",
    },
    hidden: true,
    children: [
      {
        path: "account-info",
        name: "AccountInfo",
        component: () => import("@/views/personal/account-info"),
        meta: {
          title: "账户信息",
          noKeepAlive: true,
          icon: "user",
        },
      },
      {
        path: "pwd",
        name: "pwd",
        component: () => import("@/views/personal/pwd"),
        meta: {
          title: "修改密码",
          noKeepAlive: true,
          icon: "pen-square",
        },
      },
      {
        path: "message",
        name: "Message",
        component: () => import("@/views/message/index"),
        meta: {
          title: "系统消息",
          noKeepAlive: true,
        },
      },
    ],
  },
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index"),
      },
    ],
  },
]

/*当settings.js里authentication配置的是intelligence时，views引入交给前端配置*/
export const asyncRoutes = [
  // {
  //   path: "/systems",
  //   component: Layout,
  //   redirect: "noRedirect",
  //   meta: {
  //     title: "系统管理",
  //     icon: "cogs",
  //   },
  //   children: [
  //     {
  //       path: "field-config",
  //       name: "FieldConfig",
  //       component: () => import("@/views/systems/field-config/index"),
  //       meta: {
  //         title: "字段配置",
  //         noKeepAlive: true,
  //         icon: "bars",
  //       },
  //     },
  //     {
  //       path: "form-config",
  //       name: "FormConfig",
  //       component: () => import("@/views/systems/form-config/index"),
  //       meta: {
  //         title: "表单配置",
  //         noKeepAlive: true,
  //         icon: "bars",
  //       },
  //     },
  //     {
  //       path: "user",
  //       name: "user",
  //       component: () => import("@/views/systems/user/index"),
  //       meta: {
  //         title: "用户管理",
  //         icon: "user",
  //       },
  //     },
  //     {
  //       path: "role",
  //       name: "role",
  //       component: () => import("@/views/systems/role/index"),
  //       meta: {
  //         title: "角色管理",
  //         icon: "users-cog",
  //       },
  //     },
  //     {
  //       path: "menu",
  //       name: "menuIndex",
  //       component: () => import("@/views/systems/menus/index"),
  //       meta: {
  //         title: "菜单管理",
  //         noKeepAlive: true,
  //         icon: "bars",
  //       },
  //     },
  //   ],
  // },
  {
    path: "*",
    redirect: "/404",
    hidden: true,
  },
]

const router = new VueRouter({
  mode: "hash",
  scrollBehavior(to, from, savedPosition) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve({
          x: 0,
          y: (savedPosition && savedPosition.y) || 0,
        })
      }, 500)
    })
  },
  routes: constantRoutes,
})

export function resetRouter() {
  router.matcher = new VueRouter({
    mode: "hash",
    scrollBehavior(to, from, savedPosition) {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve({
            x: 0,
            y: (savedPosition && savedPosition.y) || 0,
          })
        }, 500)
      })
    },
    routes: constantRoutes,
  }).matcher
}

export default router
