import Vue from 'vue'
import VueRouter from 'vue-router'
import genRoutes from '../utils/genRoutes'

Vue.use(VueRouter)
const salePageRoutes = genRoutes({
  publicPath: '/public/:slug'
}).map(({ name, path }) => {
  const route = {
    name,
    path,
    component: () => import('../views/html-loader/HtmlLoader.vue')
  }
  switch (name) {
    case 'SalePage':
      return {
        ...route,
        props: {
          fileName: 'landing.html'
        }
      }
    case 'SalePageProducts':
      return {
        ...route,
        props: {
          fileName: 'products.html'
        }
      }
    case 'SalePageCategoryProducts':
      return {
        ...route,
        props: {
          fileName: 'products.html'
        }
      }
    case 'SalePageProductDetail':
      return {
        ...route,
        props: {
          fileName: 'product.html'
        }
      }
    case 'SalePageCollection':
      return {
        ...route,
        props: {
          fileName: 'products.html'
        }
      }
    case 'SalePageCategoryCollection':
      return {
        ...route,
        props: {
          fileName: 'products.html'
        }
      }
    case 'SalePageCollectionDetail':
      return {
        ...route,
        props: {
          fileName: 'product.html'
        }
      }
    case 'SalePageCheckout':
      return {
        ...route,
        props: {
          fileName: 'checkout.html'
        }
      }
    case 'SalePagePayment':
      return {
        ...route,
        props: {
          fileName: 'payment.html'
        }
      }
    case 'SalePageCart':
      return {
        ...route,
        props: {
          fileName: 'cart.html'
        }
      }
    case 'SalePageOrders':
      return {
        ...route,
        props: {
          fileName: 'orders.html'
        }
      }
    case 'SalePageOrder':
      return {
        ...route,
        props: {
          fileName: 'order.html'
        }
      }
    default:
      return route
  }
})
const routes = [
  {
    path: '/editor/:slug',
    name: 'Editor',
    component: () => import('../views/editor/Editor.vue')
  },
  ...salePageRoutes
]

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

export default router
