import Vue from 'vue'
import Router from 'vue-router'
// import demo from './moudules/demo'
import myBusiness from './moudules/myBusiness'
import myTrade from './moudules/myTrade'
import mySettlement from './moudules/mySettlement'
import myAccount from './moudules/myAccount'
import myFinancing from './moudules/myFinancing'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    redirect: '/login/tradeSinceLink',
    // children: [
    //   {
    //     path: 'tradeSinceLink',
    //     component: () => import('@/views/login/components/TradeSinceLink.vue')
    //   },
    //   {
    //     path: 'qualificationsHonors',
    //     component: () => import('@/views/login/components/QualificationsHonors.vue')
    //   },
    //   {
    //     path: 'aboutUs',
    //     component: () => import('@/views/login/components/AboutUs.vue')
    //   },
    //   {
    //     path: 'contactUs',
    //     component: () => import('@/views/login/components/ContactUs.vue')
    //   }
    // ]
    children: [
      {
        path: 'tradeSinceLink',
        component: () => import('@/views/login/components/TradeSinceLinkTemp.vue')
      },
      {
        path: 'qualificationsHonors',
        component: () => import('@/views/login/components/QualificationsHonorsTemp.vue')
      },
      {
        path: 'aboutUs',
        component: () => import('@/views/login/components/AboutUsTemp.vue')
      },
      {
        path: 'contactUs',
        component: () => import('@/views/login/components/ContactUsTemp.vue')
      },
      {
        path: 'register',
        // component: () => import('@/views/login/components/register.vue')
        component: () => import('@/views/login/components/TradeSinceLinkTemp.vue')
      }
    ]
  },
  {
    path: '/perview',
    component: () => import('@/views/perview/index'),
    hidden: true
  },
  {
    path: '/about',
    component: () => import('@/views/perview/about'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '用户中心', icon: 'home', breadcrumb: false }
    }]
  },
  // demo,
  myBusiness,
  myTrade,
  myFinancing,
  mySettlement,
  myAccount

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  base: '/tfc',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
