import Vue from 'vue';
import Router from 'vue-router';
// import store from '@/store/index';
// import bus from '../assets/eventBus.js';
import VueClipboard from 'vue-clipboard2';
import main from '../views/main';
import gift from '../views/goods/gift/gift';
// import giftInfo from '../views/goods/gift/info';
import giftDetail from '../views/goods/gift/detail';
import coupon from '../views/goods/coupon/coupon';
import soldStatistics from '../views/goods/soldStatistics/statistics';
import flashSale from '../views/activities/flashSale/list';
import flashSaleInfo from '../views/activities/flashSale/detail';
// import couponInfo from '../views/goods/coupon/info';
import couponDetail from '../views/goods/coupon/detail';
import giftExchange from '../views/order/giftExchange';
import couponExchange from '../views/order/couponExchange';
import refundList from '../views/order/refundList';
import deliverSet from '../views/setting/deliverSet';
import editDeliver from '../views/setting/editDeliver';
import orderDetail from '../views/order/orderDetail';
import recordList from '../views/setting/recordList';
import convenSet from '../views/setting/convenSet';
import ruleList from '../views/goods/ruleList/ruleList';
import ruleInfo from '../views/goods/ruleList/info';
Vue.use(VueClipboard);

/**
 * meta useMenuLimit 被上标记为true的路由，进入时将会与store中允许的菜单路由进行比较，如果不存在将会被重定向
 */
const router = new Router({
  routes: [
    {
      path: '/',
      name: 'main',
      component: main,
      children: [
        {
          path: '/gift',
          name: 'gift',
          component: gift,
          meta: {
            useMenuLimit: true,
          },
        },
        {
          path: '/giftAdd',
          name: 'giftAdd',
          component: giftDetail,
          meta: {
            type: 'add',
          },
        },
        {
          path: '/giftEdit',
          name: 'giftEdit',
          component: giftDetail,
          meta: {
            type: 'edit',
          },
        },
        {
          path: '/giftInfo',
          name: 'giftInfo',
          component: giftDetail,
          meta: {
            type: 'info',
          },
        },
        {
          path: '/giftCopy',
          name: 'giftCopy',
          component: giftDetail,
          meta: {
            type: 'copy',
          },
        },
        {
          path: '/coupon',
          name: 'coupon',
          component: coupon,
          meta: {
            useMenuLimit: true,
          },
        },
        {
          path: '/couponAdd',
          name: 'couponAdd',
          component: couponDetail,
          meta: {
            type: 'add',
          },
        },
        {
          path: '/couponInfo',
          name: 'couponInfo',
          component: couponDetail,
          meta: {
            type: 'info',
          },
        },
        {
          path: '/couponEdit',
          name: 'couponEdit',
          component: couponDetail,
          meta: {
            type: 'edit',
          },
        },
        {
          path: '/couponCopy',
          name: 'couponCopy',
          component: couponDetail,
          meta: {
            type: 'copy',
          },
        },
        {
          path: '/soldStatistics',
          name: 'soldStatistics',
          component: soldStatistics,
        },
        {
          path: '/flashSale',
          name: 'flashSale',
          component: flashSale,
          meta: {
            useMenuLimit: true,
          },
        },
        {
          path: '/flashSaleAdd',
          name: 'flashSaleAdd',
          component: flashSaleInfo,
        },
        {
          path: '/flashSaleInfo',
          name: 'flashSaleInfo',
          component: flashSaleInfo,
        },
        {
          path: '/ruleList',
          name: 'ruleList',
          component: ruleList,
          meta: {
            useMenuLimit: true,
          },
        },
        {
          path: '/editRule/:id',
          name: 'editRule',
          component: ruleInfo,
          meta: {
            type: 'edit',
          },
        },
        {
          path: '/addRule',
          name: 'addRule',
          component: ruleInfo,
          meta: {
            type: 'add',
          },
        },
        {
          path: '/copyRule/:id',
          name: 'copyRule',
          component: ruleInfo,
          meta: {
            type: 'copy',
          },
        },
        {
          path: '/giftExchange',
          name: 'giftExchange',
          component: giftExchange,
          meta: {
            useMenuLimit: true,
          },
        },
        {
          path: '/orderDetail',
          name: 'orderDetail',
          component: orderDetail,
        },
        {
          path: '/couponExchange',
          name: 'couponExchange',
          component: couponExchange,
          meta: {
            useMenuLimit: true,
          },
        },
        {
          path: '/refundList',
          name: 'refundList',
          component: refundList,
          meta: {
            useMenuLimit: true,
          },
        },
        {
          path: '/deliverSet',
          name: 'deliverSet',
          component: deliverSet,
          meta: {
            useMenuLimit: true,
          },
        },
        {
          path: '/addDeliver',
          name: 'addDeliver',
          component: editDeliver,
        },
        {
          path: '/editDeliver',
          name: 'editDeliver',
          component: editDeliver,
        },
        {
          path: '/recordList',
          name: 'recordList',
          component: recordList,
          meta: {
            useMenuLimit: true,
          },
        },
        {
          path: '/convenSet',
          name: 'convenSet',
          component: convenSet,
          meta: {
            useMenuLimit: true,
          },
        },
      ],
    },
  ],
});

// router.beforeEach((to, from, next) => {
//   if (to.meta.useMenuLimit == true) {
//     if (store.state.product.canUseMenuUrl.includes(to.path)) {
//       next();
//     } else {
//       // 不允许访问则重置到menu的第一个路由
//       // 全部不选（没有积分商城任何菜单时，limit.js catch
//       bus.$emit('updateLeft', store.state.product.canUseMenuUrl[0]); // 更新左侧
//       next(store.state.product.canUseMenuUrl[0]);
//     }
//   } else {
//     next();
//   }
// });

export default router;
