import type { Component } from 'vue';
import { defineAsyncComponent, h } from 'vue';
import type { RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';
import type { MenuDataItem } from './typing';
import Layout from '@/layouts/index.vue';
import UserLayout from '@/layouts/user-layout.vue';
import UserLayout2 from '@/layouts/user-layout2.vue';
import RouteView from '@/layouts/route-view.vue';

export const routes: MenuDataItem[] = [];

export const staticRoutes: MenuDataItem[] = [
  // {
  //   path: '/wujie',
  //   name: 'wujie',
  //   redirect: '/wujie1',
  //   meta: { title: '微前端test' },
  //   // component: (): Component => import(/* webpackChunkName: "other" */ '@/views/Wujie/Wujie.vue'),
  //   children: [
  //     {
  //       path: '/wujie1',
  //       name: 'wujie1',
  //       meta: { title: 'antd' },
  //       component: (): Component =>
  //         import(/* webpackChunkName: "other" */ '@/views/Wujie/Wujie.vue'),
  //     },
  //     {
  //       path: '/wujie2',
  //       name: 'wujie2',
  //       meta: { title: 'element' },
  //       component: (): Component =>
  //         import(/* webpackChunkName: "other" */ '@/views/Wujie/Wujie2.vue'),
  //     },
  //   ],
  // },
  // {
  //   path: '/home',
  //   name: 'home',
  //   meta: { hideInMenu: false, icon: 'HeartOutlined', title: 'Home' },
  //   // component: () => import(/* webpackChunkName: "dashboard" */ '@/views/platform/Home/Index.vue'),
  //   component: (): Component => import(/* webpackChunkName: "other" */ '@/views/platform/Home/Index.vue'),
  // },
   {
    path: '/home',
    name: 'home',
    meta: { hideInMenu: false, icon: 'HeartOutlined', title: 'Home' },
    // component: () => import(/* webpackChunkName: "dashboard" */ '@/views/platform/Home/Index.vue'),
    component: (): Component => import(/* webpackChunkName: "other" */ '@/views/platform/Home/Index.vue'),
  },
  {
    path: '/user',
    name: 'user',
    meta: { hideInMenu: true, title: 'pages.layouts.userLayout.title' },
    component: UserLayout2,
    children: [
      {
        path: '/user/login',
        name: 'login',
        meta: { title: 'pages.login.accountLogin.tab' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/platform/User/Login.vue'),
      },
      {
        path: '/user/register',
        name: 'register',
        meta: { title: 'pages.login.registerAccount' },
        component: () =>
          import(/* webpackChunkName: "user" */ '@/views/platform/User/Register.vue'),
      },
      {
        path: '/user/register-result',
        name: 'register-result',
        meta: { title: 'pages.login.registerAccount' },
        component: () =>
          import(/* webpackChunkName: "user" */ '@/views/platform/User/Register-result.vue'),
      },
    ],
  },
  {
    path: '/error',
    name: 'error',
    meta: { title: 'form.basicform.basic.title' },
    component: (): Component => import(/* webpackChunkName: "other" */ '@/views/page/Error.vue'),
  },
  {
    path: '/nonav',
    name: 'nonav',
    meta: { title: 'form.basicform.basic.title' },
    component: (): Component => import(/* webpackChunkName: "other" */ '@/views/page/NoNav.vue'),
  }
];

const router = createRouter({
  history: createWebHistory(process.env.VUE_APP_PUBLIC_PATH),
  routes: staticRoutes as RouteRecordRaw[],
  scrollBehavior: (to, from) => {
    if (to.path !== from.path) {
      setTimeout(() => {
        document.getElementById('app').scrollTop = 0;
      });
    }
    return { top: 0 };
  },
});

export default router;
