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

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 },
    name:'login'
  },
  {
    path: "/signSucceed",
    component: () => import("@/views/signSucceed/index.vue"),
    meta: { hidden: true },
  },
  // 创建视频
  {
    path: "/",
    component: Layout,
    redirect: "/createVideo",
    children: [
      {
        path: "createVideo",
        component: () => import("@/views/createVideo/index.vue"),
        name: "createVideo",
        meta: {
          title: "createVideo",
          icon: "homepage",
          affix: true,
          name: "createVideo.title",
        },
      },
    ],
  },
  // 视频列表
  {
    path: "/",
    component: Layout,
    redirect: "/myCreating",
    children: [
      {
        path: "myCreating",
        component: () => import("@/views/myCreating/index.vue"),
        name: "myCreating",
        meta: {
          title: "myCreating",
          icon: "homepage",
          affix: true,
          name: "myCreating.title",
        },
      },
    ],
  },
  // 个人账户
  {
    path: "/",
    component: Layout,
    redirect: "/myAccount",
    children: [
      {
        path: "myAccount",
        component: () => import("@/views/myAccount/index.vue"),
        name: "myAccount",
        meta: {
          title: "myAccount",
          icon: "homepage",
          affix: true,
          name: "account.title",
        },
      },
    ],
  }, 
  // 商店
  {
    path: "/",
    component: Layout,
    redirect: "/myStore",
    children: [
      {
        path: "myStore",
        component: () => import("@/views/myStore/index.vue"),
        name: "myStore",
        meta: {
          title: "myStore",
          icon: "homepage",
          affix: true,
          name: "shop.title",
        },
      },
    ],
  },
  // API Access
  {
    path: "/",
    component: Layout,
    redirect: "/APIAccess",
    children: [
      {
        path: "APIAccess",
        component: () => import("@/views/APIAccess/index.vue"),
        name: "APIAccess",
        meta: {
          title: "APIAccess",
          icon: "homepage",
          affix: true,
          name: "API Access",
        },
      },
    ],
  },
  // 测试页面
  {
    path: "/",
    component: Layout,
    redirect: "/moveImg",
    children: [
      {
        path: "moveImg",
        component: () => import("@/views/moveImg/index.vue"),
        name: "moveImg",
        meta: {
          title: "moveImg",
          icon: "homepage",
          affix: true,
          name: "moveImg.title",
        },
      },
    ],
  },
  // {
  //   path: "/dashboard",
  //   component: Layout,
  //   redirect: "/dashboard",
  //   children: [
  //     {
  //       path: "dashboard",
  //       component: () => import("@/views/dashboard/index.vue"),
  //       name: "Dashboard",
  //       meta: { title: "dashboard", icon: "homepage", affix: true },
  //     },
  //     {
  //       path: "401",
  //       component: () => import("@/views/error-page/401.vue"),
  //       meta: { hidden: true },
  //     },
  //     {
  //       path: "404",
  //       component: () => import("@/views/error-page/404.vue"),
  //       meta: { hidden: true },
  //     },
  //   ],
  // },

  // 外部链接
  /*{
        path: '/external-link',
        component: Layout,
        children: [
            {
                path: 'https://www.cnblogs.com/haoxianrui/',
                meta: { title: '外部链接', icon: 'link' }
            }
        ]
    }*/
  // 多级嵌套路由
  /* {
         path: '/nested',
         component: Layout,
         redirect: '/nested/level1/level2',
         name: 'Nested',
         meta: {title: '多级菜单', icon: 'nested'},
         children: [
             {
                 path: 'level1',
                 component: () => import('@/views/nested/level1/index.vue'),
                 name: 'Level1',
                 meta: {title: '菜单一级'},
                 redirect: '/nested/level1/level2',
                 children: [
                     {
                         path: 'level2',
                         component: () => import('@/views/nested/level1/level2/index.vue'),
                         name: 'Level2',
                         meta: {title: '菜单二级'},
                         redirect: '/nested/level1/level2/level3',
                         children: [
                             {
                                 path: 'level3-1',
                                 component: () => import('@/views/nested/level1/level2/level3/index1.vue'),
                                 name: 'Level3-1',
                                 meta: {title: '菜单三级-1'}
                             },
                             {
                                 path: 'level3-2',
                                 component: () => import('@/views/nested/level1/level2/level3/index2.vue'),
                                 name: 'Level3-2',
                                 meta: {title: '菜单三级-2'}
                             }
                         ]
                     }
                 ]
             },
         ]
     }*/
];

/**
 * 创建路由
 */
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;
