import Router from 'vue-router';
import Vue from 'vue';
import shopeeRouter from './shopee';
import tiktokRouter from './tiktok';
import { isPopupEnv } from '@/browser/api';
import validatorRouter from './validator';

Vue.use(Router);

const isUsePpopup = isPopupEnv;

const utilsRouter = [
  {
    path: '/printer/log',
    component: () => import('@/vue/views/PdfLog/Index.vue'),
    name: 'PdfLog',
    meta: {
      layout: 'default',
      pageTitleKey: 'ORDER_PRINT_PDF_LOG',
      pageIcon: 'fa fa-file-pdf-o',
      requireAuth: true,
    },
  },
  {
    path: '/printer/popup',
    component: () => import('@/vue/views/Printer/Popup.vue'),
    name: 'PrinterPopup',
    beforeEnter: validatorRouter.printerPdf,
    meta: {
      layout: 'popup',
      pageTitleKey: 'PRINTER_PDF',
      requireAuth: true,
    },
  },
  {
    path: '/printer/index',
    component: () => import('@/vue/views/Printer/Index.vue'),
    name: 'PrinterIndex',
    beforeEnter: validatorRouter.printerPdf,
    meta: {
      layout: 'default',
      pageTitleKey: 'PRINTER_PDF_TOOL',
      pageIcon: 'fa fa-print',
      requireAuth: true,
    },
  },
  {
    path: '/printer/config',
    component: () => import('@/vue/views/Printer/Config.vue'),
    name: 'PrinterConfig',
    meta: {
      layout: 'default',
      pageTitleKey: 'PRINTER_CONFIG',
      pageIcon: 'fa fa-print',
    },
  },
];

const loginRouter = [
  {
    path: '/login',
    component: () => import('@/vue/views/Login/Index.vue'),
    name: 'Login',
    meta: {
      layout: isUsePpopup ? 'popup' : 'default',
      pageTitleKey: 'LOGIN_PAGE',
      pageIcon: 'fa fa-user',
    },
  },
  {
    path: '/register',
    component: () => import('@/vue/views/Login/Register.vue'),
    name: 'Register',
    meta: {
      layout: isUsePpopup ? 'popup' : 'default',
      pageTitleKey: 'BTN_REGISTER',
      pageIcon: 'fa fa-user-plus',
    },
  },
];

const settingsRouter = [
  {
    path: '/setting',
    component: () => import('@/vue/views/Setting/Index.vue'),
    name: 'Setting',
    meta: {
      layout: isUsePpopup ? 'popup' : 'default',
      pageTitleKey: 'SETTING',
      pageIcon: 'fa fa-cog',
    },
  },
  {
    path: '/upgrade-plan',
    component: () => import('@/vue/components/Single/UpgradePlan.vue'),
    name: 'UpgradePlan',
    meta: {
      layout: isUsePpopup ? 'popup' : 'default',
      pageTitleKey: 'UPGRADE_PLAN',
      pageIcon: 'fa fa-credit-card',
      requireAuth: true,
    },
  },
];

const listCoreRouter = [...settingsRouter, ...loginRouter, ...utilsRouter, ...shopeeRouter, ...tiktokRouter];

const routes = [
  {
    path: '/',
    redirect: '/shopee/tab/all',
  },
  {
    path: '/app',
    component: () => import('@/vue/views/Single/App.vue'),
    meta: {
      layout: 'popup',
    },
  },
  ...listCoreRouter,
  {
    path: '/:pathMatch(.*)*',
    component: () => import('@/vue/views/Single/404.vue'),
    name: 'NotFound',
    meta: {
      layout: 'default',
      pageTitleKey: 'PAGE_NOT_FOUND_404',
      showPageHeader: false,
    },
  },
];

export default new Router({
  scrollBehavior: () => ({
    y: 0,
  }),
  routes,
});
