import { THIRD_PARTY_APP_PRODUCT_VIEWER } from '@/config/url-prefix'
import { IS_LOGGED_IN_GETTER_NAME, IS_LOGGED_IN_GUEST_GETTER_NAME } from '@/config/defaults'
import { SELECTED_COUNTRY } from '@/store/utils/localStorageKeys'

export default {
  name: 'thirdPartyAppsProductViewer',
  type: 'path',
  match: [THIRD_PARTY_APP_PRODUCT_VIEWER],
  inAppArea: async function(app) {
    if (
      app.$store.getters[IS_LOGGED_IN_GUEST_GETTER_NAME] === null ||
      app.$store.getters[IS_LOGGED_IN_GUEST_GETTER_NAME] === false ||
      app.$store.getters[IS_LOGGED_IN_GUEST_GETTER_NAME] === 'false'
    ) {
      if (
        app.$store.getters[IS_LOGGED_IN_GETTER_NAME] === null ||
        app.$store.getters[IS_LOGGED_IN_GETTER_NAME] === false ||
        app.$store.getters[IS_LOGGED_IN_GETTER_NAME] === 'false'
      ) {
        let query = '?medium=enrolment&referrer='
        await app.$store.dispatch('guestLogin', query)
      }
    }
    if (localStorage.getItem(SELECTED_COUNTRY) === null) {
      await app.$store.dispatch('updateUserCountryById', false)
    }
  },
  outAppArea: function() {},
}
