import { DefaultHeader, DefaultFooter } from '@@/app/_global/components/blocks'
import { SHOW_HEADER, SHOW_FOOTER } from '@@/store/localStorageKeys'
import { THIRD_PARTY_APP_CHECKOUT, THIRD_PARTY_APP_CHECKOUT_MEMBERSHIP } from '@/config/url-prefix'

const requireComponent = require.context(
  // Look for files in the current directory
  './',
  // Look in  subdirectories
  true,
  // Only include "_base-" prefixed .vue files
  /_router.js$/
)

let subRoutes = []
// For each matching file name...
requireComponent.keys().forEach(fileName => {
  // remove _ to turn route off
  if (fileName.indexOf('_') > 0) {
    subRoutes = [...subRoutes, ...requireComponent(fileName).default]
  }
})

export default [
  {
    path: '/',
    component: () => {
      return import('@@/layouts/BaseLayout')
    },
    props: route => ({
      showHeader: !!(route.query.showHeader === 'true' || localStorage.getItem(SHOW_HEADER)),
      showFooter: !!(route.query.showFooter === 'true' || localStorage.getItem(SHOW_FOOTER)),
    }),
    meta: {
      template: {
        header: DefaultHeader,
        footer: DefaultFooter,
        containerClass: 'checkout-screen',
      },
    },
    children: [
      {
        path: THIRD_PARTY_APP_CHECKOUT,
        redirect: { name: THIRD_PARTY_APP_CHECKOUT_MEMBERSHIP },
        component: () => import('@@/app/checkout/CheckoutTemplate'),
        children: [...subRoutes],
      },
    ],
  },
]
