import Vue from 'vue'
import VueRouter, { RawLocation, RouteConfig, Route } from 'vue-router'
// import App from '../App.vue'
import { teamRoutes } from './team'
// import { attendanceRoutes } from './attendance'
// import { clientRoutes } from './client'
// import { okrRoutes } from './okr'
// import { scheduleRoutes } from './schedule'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push as unknown as Promise<Route>
const originalReplace = VueRouter.prototype.replace as unknown as Promise<Route>
// push
VueRouter.prototype.push = function push (location: RawLocation) {
  return (originalPush as any).call(this, location).catch((err: Error) => err)
}
// replace
VueRouter.prototype.replace = function (location: RawLocation) {
  return (originalReplace as any).call(this, location).catch((err: Error) => err)
}

const routes: Array<RouteConfig> = [
  {
    path: '/',
    name: 'Home',
    redirect: '/team',
    meta: {
      title: '首页'
    }
  },
  ...teamRoutes,
  // ...attendanceRoutes,
  // ...clientRoutes,
  // ...okrRoutes,
  // ...scheduleRoutes
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
