import AccountsReceivable from "./../pages/accountsReceivable.vue"
import NewReport from "./../pages/newReport.vue"
import NewResult from "../pages/newResults.vue"
import Results from "./../pages/results.vue"
import Report from "./../pages/report.vue"
import Stock from "./../pages/stock.vue"
import Login from "./../pages/login.vue"
import Index from "../pages/index.vue"
import NewResultChart from "../pages/newResultsChart.vue"
import NewResultInfo from "../pages/newResultsInfo.vue"

import { getParameterByName } from "../utils/auth"

const routes = [
  { path:"/", component: Index },
  { path:'/report', component: Report },
  { path:'/login', component: Login} ,
  { path:'/newReport', component: NewReport },
  { path:'/results', component: Results },
  { path:'/accountsReceivable', component: AccountsReceivable },
  { path:'/stock', component: Stock },
  { path:'/newResults', component: NewResult },
  { path:'/newResultChart', component: NewResultChart },
  { path:'/newResultInfo', component: NewResultInfo },
]

const router = new VueRouter({routes, mode:'hash'})

router.beforeEach((to, _, next) => {
  const path = getParameterByName('path')
  if(to.path === "/" && !path){
    next()
  }else if (to.path !== '/login' && !getParameterByName('code')) {
    next({ path:'login', query: { path } })
  } else {
    next();
  }
})

export default router
