import { getSession, setSession } from '@/utils/sessionStorage'
import { getProductVacationList } from "@/api/product";
const market = {
  state: {
    marketCN: null,
    marketHK: null,
    marketUS: null,
    marketCFD: null,

    marketPopCN: getSession('marketPopCN'),
    marketPopHK: getSession('marketPopHK'),
    marketPopUS: getSession('marketPopUS'),
    marketPopCFD: getSession('marketPopCFD'),
  },
  mutations: {
    setMarket: (state, params) => {
      state['market' + params.key] = params.value
    },
    setMarketPop: (state, market) => {
      state['marketPop' + market] = true
      setSession('marketPop' + market, true)
    },
  },
  actions: {
    getProductVacationList({ commit, state }, market) {
      return new Promise((resolve, reject) => {
        getProductVacationList({market}).then(res => {
          var list = res.list || []
          commit('setMarket', {
            key: market,
            value: list[0] || {}
          })
          resolve()
        }).catch(error => {
        })
      })
    },
  }
}

export default market
