import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = () => new Vuex.Store({
  state: {
    isPC: -1,
    isWeixin: false,
    userinfo: {},
    wxConfig: {},
  },
  getters: {
    isLogin(state) {
      return !!state.userinfo.nickname
    }
  },
  mutations: {
    updateUserinfo(state, payload) {
      state.userinfo = payload.userinfo
    },
    updateIsPC(state, payload) {
      state.isPC = payload.isPC
    },
    updateIsWeixin(state, payload) {
      state.isWeixin = payload.isWeixin
    },
    updateWxConfig(state, payload) {
      state.wxConfig = {
        ...state.wxConfig,
        ...payload.wxConfig,
      }
    }
  }
})

export default store