import { createRouter, createWebHashHistory } from 'vue-router'
import { useUserStore } from './stores/user'

const routes = [
  {
    path: '/',
    name: 'Index',
    component: () => import('./views/Index.vue'),
    redirect: '/Home',
    children: [
      {
        path: '/Home',
        name: 'Home',
        component: () => import('./views/Tabbars/Home.vue'),
        meta: { title: '主页', cache: true }
      },
      {
        path: '/Gift',
        name: 'Gift',
        component: () => import('./views/Tabbars/Gift.vue'),
        meta: { title: '礼包区', cache: true }
      },
      {
        path: '/Mall',
        name: 'Mall',
        component: () => import('./views/Tabbars/Mall.vue'),
        meta: { title: '商城', cache: true }
      },
      {
        path: '/PointMall',
        name: 'PointMall',
        component: () => import('./views/Tabbars/PointMall.vue'),
        meta: { title: '积分区', cache: true }
      },
      {
        path: '/My',
        name: 'My',
        component: () => import('./views/User/My.vue'),
        meta: { title: '我的' }
      },
    ],
    meta: { noLogin: true }
  },
  {
    path: '/WxCallback',
    name: 'WxCallback',
    component: () => import('./views/Account/WxCallback.vue'),
    meta: {
      noLogin: true,
    }
  },
  {
    path: '/Login',
    name: 'Login',
    component: () => import('./views/Account/Login.vue'),
    meta: {
      title: '登录',
      noLogin: true,
      noRefresh: true,
    }
  },
  {
    path: '/ResetPwd',
    name: 'ResetPwd',
    component: () => import('./views/Account/ResetPwd.vue'),
    meta: {
      title: '找回密码',
      noLogin: true,
    }
  },
  {
    path: '/Balance',
    name: 'Balance',
    component: () => import('./views/User/Wallet/Balance.vue'),
    meta: {
      title: '余额',
    }
  },
  {
    path: '/CV',
    name: 'CV',
    component: () => import('./views/User/Wallet/CV.vue'),
    meta: {
      title: '会员卡',
    }
  },
  {
    path: '/Point',
    name: 'Point',
    component: () => import('./views/User/Wallet/Point.vue'),
    meta: {
      title: '积分',
    }
  },
  {
    path: '/Allow',
    name: 'Allow',
    component: () => import('./views/User/Wallet/Allow.vue'),
    meta: {
      title: '业绩统计',
    }
  },
  {
    path: '/Certificate',
    name: 'Certificate',
    component: () => import('./views/User/Wallet/Certificate.vue'),
    meta: {
      title: '礼品券',
    }
  },
  {
    path: '/Transfer',
    name: 'Transfer',
    component: () => import('./views/User/Wallet/Transfer.vue'),
    meta: {
      title: '互转',
    }
  },
  {
    path: '/CashoutRecord',
    name: 'CashoutRecord',
    component: () => import('./views/Cashout/CashoutRecord.vue'),
    meta: {
      title: '提现记录',
    }
  },
  {
    path: '/Cashout',
    name: 'Cashout',
    component: () => import('./views/Cashout/Cashout.vue'),
    meta: {
      title: '提现',
    }
  },
  {
    path: '/Service',
    name: 'Service',
    component: () => import('./views/User/Service.vue'),
    meta: { title: '客服中心' }
  },
  {
    path: '/Address',
    name: 'Address',
    component: () => import('./views/User/Address.vue'),
    meta: { title: '收货地址' }
  },
  {
    path: '/Invite',
    name: 'Invite',
    component: () => import('./views/User/Invite.vue'),
    meta: { title: '邀请码', cache: true }
  },
  {
    path: '/Team',
    name: 'Team',
    component: () => import('./views/User/Team.vue'),
    meta: { title: '我的好友' }
  },
  {
    path: '/CashoutAccount',
    name: 'CashoutAccount',
    component: () => import('./views/Cashout/CashoutAccount.vue'),
    meta: { title: '提现账号' }
  },
  {
    path: '/TradeConfirm',
    name: 'TradeConfirm',
    component: () => import('./views/Trade/TradeConfirm.vue'),
    meta: { title: '确认订单' }
  },
  {
    path: '/TradeDetail',
    name: 'TradeDetail',
    component: () => import('./views/Trade/TradeDetail.vue'),
    meta: { title: '订单详情' }
  },
  {
    path: '/TradeList',
    name: 'TradeList',
    component: () => import('./views/Trade/TradeList.vue'),
    meta: { title: '订单列表' }
  },
  {
    path: '/Pay',
    name: 'Pay',
    component: () => import('./views/Trade/Pay.vue'),
    meta: { title: '支付' }
  },
  {
    path: '/Business_School',
    name: 'Business_School',
    component: () => import('./views/Platform/Business_School.vue'),
    meta: { title: '商学院', noLogin: true }
  },
  {
    path: '/School_detail',
    name: 'School_detail',
    component: () => import('./views/Platform/School_Detail.vue'),
    meta: { title: '商学院详情', noLogin: true, }
  },
  {
    path: '/School_Category',
    name: 'School_Category',
    component: () => import('./views/Platform/School_Category.vue'),
    meta: { title: '商学院分类', noLogin: true, }
  },
  {
    path: '/Column',
    name: 'Column',
    component: () => import('./views/Platform/Column.vue'),
    meta: { title: '栏目列表', noLogin: true }
  },
  {
    path: '/ColumnDetail',
    name: 'ColumnDetail',
    component: () => import('./views/Platform/ColumnDetail.vue'),
    meta: { title: '栏目详情', noLogin: true }
  },
  {
    path: '/GoodsDetail',
    name: 'GoodsDetail',
    component: () => import('./views/Goods/GoodsDetail.vue'),
    meta: { title: '商品详情', noLogin: true, }
  },
  {
    path: '/Category',
    name: 'Category',
    component: () => import('./views/Goods/Category.vue'),
    meta: { title: '全部分类', noLogin: true, }
  },
  {
    path: '/Operations',
    name: 'Operations',
    component: () => import('./views/Operations/Operations.vue'),
    meta: { title: '运营中心' }
  },
  {
    path: '/CertificateRecord',
    name: 'CertificateRecord',
    component: () => import('./views/User/Wallet/CertificateRecord.vue'),
    meta: { title: '核销记录' }
  },
  {
    path: '/Merchant',
    name: 'Merchant',
    component: () => import('./views/Merchant/Merchant.vue'),
    meta: { title: '商家中心' }
  },
  {
    path: '/MerchantIncome',
    name: 'MerchantIncome',
    component: () => import('./views/Merchant/MerchantIncome.vue'),
    meta: { title: '营业收入' }
  },
  {
    path: '/MerchantCashout',
    name: 'MerchantCashout',
    component: () => import('./views/Merchant/MerchantCashout.vue'),
    meta: { title: '提现记录' }
  },
  {
    path: '/Statistics',
    name: 'Statistics',
    component: () => import('./views/Merchant/Statistics.vue'),
    meta: { title: '数据统计' }
  },
  {
    path: '/MerchantTrade',
    name: 'MerchantTrade',
    component: () => import('./views/Merchant/MerchantTrade.vue'),
    meta: { title: '商家订单' }
  },
  {
    path: '/MerchantTradeDetail',
    name: 'MerchantTradeDetail',
    component: () => import('./views/Merchant/MerchantTradeDetail.vue'),
    meta: { title: '订单详情' }
  },
  {
    path: '/MerchantIntroduction',
    name: 'MerchantIntroduction',
    component: () => import('./views/Merchant/MerchantIntroduction.vue'),
    meta: { title: '商家资料' }
  },
  {
    path: '/PayCode',
    name: 'PayCode',
    component: () => import('./views/Merchant/PayCode.vue'),
    meta: { title: '收款码' }
  },
  {
    path: '/QrReader',
    name: 'QrReader',
    component: () => import('./views/Operations/QrReader.vue'),
    meta: { title: '扫一扫' }
  },
  {
    path: '/Checkout',
    name: 'Checkout',
    component: () => import('./views/User/Checkout/Checkout.vue'),
    meta: { title: '买单' }
  },
  {
    path: '/CheckoutTrade',
    name: 'CheckoutTrade',
    component: () => import('./views/User/Checkout/CheckoutTrade.vue'),
    meta: { title: '订单详情' }
  },
  {
    path: '/Refresh',
    name: 'Refresh',
    component: { render: () => null },
    meta: { noLogin: true },
    beforeRouteEnter(to, from, next) {
      next(vm => {
        setTimeout(() => {
          const redirect = to.query.redirect || '/Home'
          vm.$router.replace(decodeURIComponent(redirect))
        }, 50)
      })
    }
  },
  {
    path: '/SyncAuth',
    name: 'SyncAuth',
    component: () => import('./views/SyncAuth.vue'),
    meta: {
      noLogin: true,
    }
  },
  {
    path: '/404',
    name: '404',
    component: () => import('./views/404.vue'),
    meta: {
      title: '404',
      noLogin: true,
    }
  },
  {
    path: '/:pathMatch(.*)',
    redirect: '/404'
  }
]

export { routes }
