import * as T from '@/store/utils/types'
import { ENROLMENT_SELECT_PRODUCTS } from '@/config/url-prefix'
import router from '@/router'

export default store => {
  store.subscribe(async mutation => {
    if (store.getters.getAppStatus('enrolment') === true) {
      if (mutation.type === 'eshop/' + T.ESHOP_CART_SET_ADD_PRODUCT) {
        store.dispatch('clearLoadedData', ['focpwp'])
      }
    }

    if (['enrolment/' + T.SET_ENROL_PRODUCT_SEARCH_FILTER].indexOf(mutation.type) !== -1) {
      let pagination = store.getters.getPagination('enrol-products') || { offset: 0 }
      if (pagination.offset !== 0) {
        router.push(ENROLMENT_SELECT_PRODUCTS + '/' + 1)
      }
    }
  })
}
