import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout'
import SiteRouter from './SiteRouter'
import ChargeRouter from './ChargeRouter'
import UserRouter from './UserRouterV2'
import PartnershipRouter from './PartnershipRouter'
import EnergyRouter from './EnergyRouter'
import OCPPRouter from './OCPPRouter'
import FinancialRouter from './FinancialRouter'
import IncidentRouter from './IncidentRouter'
import ActivityRouter from './ActivityRouter'
import SupportRouter from './SupportRouter'
import ReportsRouter from './ReportsRouter'
import NotificationRouter from './NotificationRouter'
import AccessRouter from './AccessRouter'
import SettingsRouter from './SettingsRouter'
import additionalRoute from './addition'

Vue.use(VueRouter)

const constantRoutes = [
  {
    path: '/',
    redirect: '/redirect'
  },
  {
    path: '/redirect',
    hidden: true,
    component: () => import('@/views/redirect/index')
  },
  {
    path: '/404',
    hidden: true,
    component: () => import('@/views/redirect/404')
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    meta: {
      title: 'Login'
    },
    hidden: true
  },
  /*{
    path: '/administrator',
    component: Layout,
    meta: {
      title: 'Administrator',
      subTitle: 'Settings',
      icon: 'administrator',
      activeIcon: 'administrator-active',
      affix: true
    },
    children: [
      {
        path: '/administrator',
        component: () => import('@/views/Administrator'),
        name: 'administrator',
        meta: {
          title: 'Administrator',
          subTitle: 'Settings',
          icon: 'administrator',
          breadcrumb: false,
        }
      }
    ],
  },*/
  {
    path: '/dashboard',
    component: Layout,
    meta: {
      title: 'Dashboard',
      icon: 'dashboard',
      activeIcon: 'dashboard-active',
      affix: true
    },
    children: [
      {
        path: '/dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'dashboard',
        meta: {
          title: 'Dashboard',
          icon: 'dashboard',
          breadcrumb: false
        }
      },
      {
        path: '/maps',
        component: () => import('@/views/dashboard/components/Maps'),
        name: 'maps',
        meta: {
          title: 'Maps',
          icon: 'dashboard',
        },
        hidden: true
      }
    ],
  },
  SiteRouter,
  ChargeRouter,
  ActivityRouter,
  IncidentRouter,
  EnergyRouter,
  FinancialRouter,
  UserRouter,
  SupportRouter,
  OCPPRouter,
  ReportsRouter,
  NotificationRouter,
  PartnershipRouter,
  AccessRouter,
  ...additionalRoute,
  /*OCPI*/
  SettingsRouter
]

const asyncRoutes = []

export {
  constantRoutes,
  asyncRoutes,
}

const createRouter = () => new VueRouter({
  // mode: 'history', // require service support
  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