<template>
  <div></div>
</template>
<script>
import { mapActions } from 'vuex'

export default {
  props: ['languageId'],
  data() {
    return {
      previousRoute: '',
    }
  },
  mounted() {},
  methods: {
    ...mapActions([
      'updateSelectedLanguage',
      'clearShoppingData',
      'loadCountries',
      'updateSelectedCountry',
      'generateMenus',
    ]),
    setLanguageAndBack() {
      return this.updateSelectedLanguage(this.languageId)
    },
  },
  beforeRouteEnter(to, from, next) {
    next(vue => {
      vue.previousRoute = from.path
      vue.setLanguageAndBack().then(() => {
        vue.loadCountries().then(() => {
          vue.updateSelectedCountry()
          vue.generateMenus()
          vue.$router.replace(vue.previousRoute)
          next()
        })
      })
    })
  },
  destroyed() {
    // force refresh the page to make master data api call again
    this.$router.go(0)
  },
}
</script>
