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

export default {
  name: 'thirdPartyAppsProductList',
  type: 'path',
  match: [THIRD_PARTY_APP_PRODUCT],
  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() {},
}
