import { CLEAR_LOADED_DATA, SET_I_TOKEN_REDEMPTION_FORM, SET_I_TOKEN_COUNTRY } from '@/store/utils/types'
import { I_TOKEN_REDEMPTION_FORM } from '@/store/utils/localStorageKeys'

export default {
  [SET_I_TOKEN_REDEMPTION_FORM](state, data) {
    state.redemptionFormData = data
    sessionStorage.setItem(I_TOKEN_REDEMPTION_FORM, JSON.stringify(data))
  },

  [SET_I_TOKEN_COUNTRY](state, data) {
    state.redemptionCountryId = data
  },

  [CLEAR_LOADED_DATA](state, type) {
    if (type === 'iToken' || !type) {
      state.redemptionCountryId = false
      state.redemptionFormData = { cart: [], shippingInfo: {} }
      sessionStorage.removeItem(I_TOKEN_REDEMPTION_FORM)
    }
  },
}
