// import VueRouter, { createWebHistory } from 'vue-router';
import VueRouter from 'vue-router';
// import qs from 'qs';
import Home from '@/pages/parkingFee/parkingFee.vue';
// import crmRouters from './crmIndex';
const routes = [
  { path: '/', name: 'index', component: Home },
  { path: '/home', name: 'home', component: Home },
  {
    path: '/parkingFeePayment',
    component: () => import('@/pages/parkingFee/parkingFeePayment.vue'),
  },
  {
    path: '/parkingFeeDetail',
    name: 'parkingFeeDetail',
    component: () => import('@/pages/parkingFee/parkingFeeDetail.vue'),
  },
  {
    path: '/parkingFeeCoupon',
    name: 'parkingFeeCoupon',
    component: () => import('@/pages/parkingFee/parkingFeeCoupon.vue'),
  },
  {
    path: '/parkingFeeDetailSuccess',
    name: 'parkingFeeDetailSuccess',
    component: () => import('@/pages/parkingFee/parkingFeeDetailSuccess.vue'),
  },
  {
    path: '/parkingFeePaperCoupon',
    name: 'parkingFeePaperCoupon',
    component: () => import('@/pages/parkingFee/parkingFeePaperCoupon.vue'),
  },
  {
    path: '/parkingFeeList',
    name: 'parkingFeeList',
    component: () => import('@/pages/parkingFee/parkingFeeList.vue'),
  },
  // {
  //   path: '/pointsMall',
  //   name: 'pointsMall',
  //   component: () => import('@/pages/pointsMall/pointsMall.vue'),
  // },
  {
    path: '/parkingReceipt',
    name: 'parkingReceipt',
    component: () =>
      import('@/pages/parkingFee/parkingReceipt/parkingReceipt.vue'),
  },
  {
    path: '/vehicleManagement',
    name: 'vehicleManagement',
    component: () => import('@/pages/parkingFee/vehicleManagement.vue'),
  },
  {
    path: '/vehicleAddOrEdit',
    name: 'vehicleAddOrEdit',
    component: () => import('@/pages/parkingFee/vehicleAddOrEdit.vue'),
  },
  {
    path: '/parkingFeeSuccess',
    name: 'parkingFeeSuccess',
    component: () => import('@/pages/parkingFee/parkingFeeSuccess.vue'),
  },
  {
    path: '/cryptojs',
    name: 'cryptojs',
    component: () => import('@/pages/cryptojs/cryptojs.vue'),
  },
  {
    path: '/parkingFeeDiscounts',
    name: 'parkingFeeDiscounts',
    component: () => import('@/pages/parkingFee/parkingFeeDiscounts.vue'),
  },
  {
    path: '/parkingFeePaperCoupon',
    name: 'parkingFeePaperCoupon',
    component: () => import('@/pages/parkingFee/parkingFeePaperCoupon.vue'),
  },
  {
    path: '/parkingInvoice',
    name: 'parkingInvoice',
    component: () =>
      import('@/pages/parkingFee/parkingReceipt/parkingInvoice.vue'),
  },
  {
    path: '/parkingHeaderDetail',
    name: 'parkingHeaderDetail',
    component: () =>
      import('@/pages/parkingFee/parkingReceipt/parkingHeaderDetail.vue'),
  },
  {
    path: '/parkingInvoiceImage',
    name: 'parkingInvoiceImage',
    component: () =>
      import('@/pages/parkingFee/parkingReceipt/parkingInvoiceImage.vue'),
  },
  {
    path: '/parkingOrderDetail',
    name: 'parkingOrderDetail',
    component: () =>
      import('@/pages/parkingFee/parkingReceipt/parkingOrderDetail.vue'),
  },
  {
    path: '/parkingApplication',
    name: 'parkingApplication',
    component: () =>
      import('@/pages/parkingFee/parkingReceipt/parkingApplication.vue'),
  },
  {
    path: '/parkingChooseHeader',
    name: 'parkingChooseHeader',
    component: () =>
      import('@/pages/parkingFee/parkingReceipt/parkingChooseHeader.vue'),
  },
  {
    path: '/parkingChangeHeader',
    name: 'parkingChangeHeader',
    component: () =>
      import('@/pages/parkingFee/parkingReceipt/parkingChangeHeader.vue'),
  },
  // 登录
  {
    path: '/login',
    name: 'login',
    component: () => import('@/pages/login/login.vue'),
  },
  // 微信授权回调
  {
    path: '/openWx',
    name: 'openWx',
    component: () => import('@/pages/login/openWx.vue'),
  },
  // 无牌车提示文案
  {
    path: '/parkingFeeMsg',
    name: 'parkingFeeMsg',
    component: () => import('@/pages/parkingFee/parkingFeeMsg.vue'),
  },
  {
    path: '/dome',
    name: 'dome',
    component: () => import('@/pages/cryptojs/demo.vue'),
  },
  // { path: '/bar', component: 'Bar' }
].map((item) => {
  let keepAlive = false;
  if (/\/parkingFeeDetail/.test(item.path)) {
    keepAlive = true;
  }
  item = {
    ...item,
    meta: {
      keepAlive, // 不需要被缓存
    },
  };
  return item;
});

const wxRoutes = routes.map((item) => {
  return {
    ...item,
    path: `/wx/:token${item.path}`,
  };
});

const otherRoutes = routes.map((item) => {
  return {
    ...item,
    path: `/:groupId/:mallId${item.path}`,
  };
});

// tparking qa 测试环境
const otherTparkingRoutes = routes.map((item) => {
  return {
    ...item,
    path: `/tparking/:groupId/:mallId${item.path}`,
  };
});

// crm 路由
// const wxRoutes = routes.map((item) => {
//   return {
//     ...item,
//     path: `/wx/:token${item.path}`,
//   };
// });

const router = new VueRouter({
  mode: 'history',
  base: '/tparking/',
  routes: [
    ...routes,
    ...wxRoutes,
    ...otherRoutes,
    ...otherTparkingRoutes,
    // ...crmRouters,
    { path: '*', component: import('@/pages/NotFoundComponent/index.vue') },
  ],
});

// router.beforeEach((to, from, next) => {
//   // let pageId = '';
//   // if (window.location.href.indexOf('pageId') > 0) {
//   //   pageId = `${window.location.href}`.replace(/.*pageId=([0-9A-Z]*).*/g, '$1');
//   // }
//   // setTimeout(() => {
//   //   if (
//   //     pageId &&
//   //     (window.location.href.indexOf('pageId') < 0 ||
//   //       to.fullPath.indexOf('pageId') < 0)
//   //   ) {
//   //     let url = `${window.location.origin}/#${to.path}?${qs.stringify({
//   //       ...to.query,
//   //       pageId,
//   //     })}`;
//   //     window.history.replaceState('', '', url);
//   //   }
//   // }, 100);
//   next();
// });
export default router;
