import * as T from '../utils/types'
import { SUBSCRIPTION } from '@/config/url-prefix'
import helpers from '@/helpers'

export default store => {
  store.subscribe(mutation => {
    if (mutation.type === T.LOGIN_USER) {
      store.dispatch('loadEnrollmentRanks')
    }
    if (
      mutation.type === T.MEMBER_SET_SUBSCRIPTION &&
      store.state.memberModule.subscription.status === false &&
      helpers.getValue(store.state.auth.rules, 'tabs.my_account_subscription_tab', false) === true
    ) {
      store.dispatch('noticeAdd', {
        message: 'MyAccount.Subscription.Expired',
        tags: ['subscription-notice'],
        link: {
          text: 'MyAccount.Subscription.Subscribe',
          url: SUBSCRIPTION,
        },
      })
    }
  })
}
