import { CLEAR_LOADED_DATA, ESHOP_SET_I_TOKEN_CART, ESHOP_SET_I_TOKEN_REDEEM_LATER_STATUS } from '@/store/utils/types'
import { ESHOP_I_TOKEN_CART, ESHOP_REDEEM_LATER_STATUS } from '@/store/utils/localStorageKeys'

export default {
  [ESHOP_SET_I_TOKEN_CART](state, items) {
    state.iTokenCart = [...items]
    sessionStorage.setItem(ESHOP_I_TOKEN_CART, JSON.stringify(items))
  },

  [ESHOP_SET_I_TOKEN_REDEEM_LATER_STATUS](state, status) {
    state.isRedeemLater = status
    sessionStorage.setItem(ESHOP_REDEEM_LATER_STATUS, JSON.stringify(status))
  },

  [CLEAR_LOADED_DATA](state, type) {
    if (type === 'iToken' || !type) {
      state.iTokenCart = []
      state.isRedeemLater = false
      sessionStorage.removeItem(ESHOP_I_TOKEN_CART)
      sessionStorage.removeItem(ESHOP_REDEEM_LATER_STATUS)
    }
  },
}
