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

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

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [

  // 登录
  {
    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: "/myStore",
    children: [
      {
        path: "myStore",
        component: () => import("@/views/myStore/index.vue"),
        name: "myStore",
        meta: {
          title: "myStore",
          icon: "homepage",
          affix: true,
          name: "myStore.title",
        },
      },
    ],
  }, {
    path: "/",
    component: Layout,
    redirect: "/myAPI",
    children: [
      {
        path: "myAPI",
        component: () => import("@/views/myAPI/index.vue"),
        name: "myAPI",
        meta: {
          title: "myAPI",
          icon: "homepage",
          affix: true,
          name: "API.title",
        },
      },
    ],
  },
  {
    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",
        },
      },
    ],
  },

];

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