import { defineComponent } from '@vue/composition-api';
import { loggerVue } from '@/plugins/logger';

export default defineComponent({
  methods: {
    openMenu({
      to, external, key, isNewTab,
    }) {
      this.SetMenuActive(key, true);

      if (external) {
        return this.openExternalUrl(external);
      }

      if (to) {
        if (this.isUsePopup && !isNewTab) {
          const popupUrl = this.createPopupUrl(to);
          return this.openExternalUrl(popupUrl);
        }

        return this.RouterPath(to);
      }

      if (key === 'logout') {
        return this.UserLogout();
      }

      loggerVue.error({
        msg: 'MENU_TO_EMPTY',
        key,
        to,
        external,
      });
    },
  },
  computed: {
    labelMenu() {
      return [this.$t('MENU_DROPDOWN'), !this.getIsAuthed ? this.$t('NO_LOGIN') : ''].filter((item) => item).join(' / ');
    },
    listMenu() {
      return [
        {
          label: this.$t('GO_LOGIN'),
          color: '',
          key: 'login',
          icon: 'fa fa-user',
          to: '/login',
          isNewTab: true,
          isPopup: true,
          isShow: !this.getIsAuthed,
        },
        {
          label: this.$t('GO_REGISTER'),
          color: '',
          key: 'register',
          icon: 'fa fa-sign-in',
          to: '/register',
          isNewTab: true,
          isPopup: true,
          isShow: !this.getIsAuthed,
        },
        {
          label: this.$t('GO_APP'),
          color: '',
          key: 'app',
          icon: 'fa fa-home',
          to: '/app',
          isNewTab: true,
          isPopup: true,
          isShow: false,
        },
        {
          label: this.$t('GO_SHOPEE_FLASHSALE'),
          color: '',
          key: 'shopee-flash-sale',
          to: '/shopee/seller/flashsale',
          icon: 'fa fa-bolt',
          isNewTab: false,
          isPopup: true,
          isShow: true,
        },
        {
          label: this.$t('GO_SHOPEE_AUTO'),
          color: '',
          key: 'shopee-auto',
          to: '/shopee/seller/auto/dashboard',
          icon: 'fa fa fa-magic',
          isNewTab: false,
          isPopup: true,
          isShow: true,
        },
        {
          label: this.$t('GO_SHOPEE_SPY'),
          color: '',
          key: 'shopee-spy',
          icon: 'fa fa-user-secret',
          to: '/shopee/spy/dashboard',
          isNewTab: false,
          isPopup: true,
          isShow: false,
        },
        {
          label: this.$t('GO_SHOPEE_MARKET'),
          color: '',
          key: 'shopee-market',
          icon: 'fa fa-balance-scale',
          to: '/shopee/spy/market',
          isNewTab: false,
          isPopup: true,
          isShow: !this.getUseShopManager,
        },
        {
          label: this.$t('GO_TIKTOK_MARKET'),
          color: '',
          key: 'tiktok-market',
          to: '/shopee/spy/tiktok',
          icon: 'fa fa-balance-scale',
          isNewTab: false,
          isPopup: true,
          isShow: false,
        },
        {
          label: this.$t('GO_SHOPEE_LIVE'),
          color: '',
          key: 'shopee-live',
          icon: 'fa fa-video-camera',
          to: '/shopee/seller/live',
          isNewTab: false,
          isPopup: true,
          isShow: false,
        },
        {
          label: this.$t('GO_SHOPEE_ADS'),
          color: '',
          key: 'shopee-ads',
          to: '/shopee/seller/ads',
          icon: 'fa fa-location-arrow',
          isNewTab: false,
          isPopup: true,
          isShow: false,
        },
        {
          label: this.$t('GO_SHOPEE_KEYWORD'),
          color: '',
          key: 'shopee-keyword',
          to: '/shopee/seller/keyword',
          icon: 'fa fa fa-book',
          isNewTab: false,
          isPopup: true,
          isShow: false,
        },
        {
          label: this.$t('GO_SETTING'),
          color: '',
          key: 'setting',
          to: '/setting',
          icon: 'fa fa-cog',
          isNewTab: true,
          isPopup: true,
          isShow: true,
        },
        {
          label: this.$t('GO_PRINTER_PDF'),
          color: '',
          key: 'printer-pdf',
          icon: 'fa fa-print',
          to: '/printer/index',
          isNewTab: false,
          isPopup: true,
          isShow: true,
        },
        {
          label: this.$t('GO_PRINTER_LOG'),
          color: '',
          key: 'printer-log',
          icon: 'fa fa-file-text-o',
          to: '/printer/log',
          isNewTab: false,
          isPopup: true,
          isShow: true,
        },
        {
          label: this.$t('GO_TUTORIAL'),
          color: '',
          key: 'tutorial',
          external: this.configApp.docUrl.home,
          icon: 'fa fa-info ',
          isNewTab: false,
          isPopup: false,
          isShow: true,
        },
        {
          label: this.$t('GO_CONTACT'),
          color: '',
          key: 'contact',
          external: this.configApp.docUrl.contact,
          icon: 'fa fa-phone ',
          isNewTab: false,
          isPopup: false,
          isShow: true,
        },
        {
          label: this.$t('LOGOUT'),
          color: '',
          key: 'logout',
          icon: 'fa fa-sign-out',
          isNewTab: false,
          isPopup: true,
          isShow: this.getIsAuthed,
        },
      ];
    },
  },
});
