import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: "",
    layers: [],
    mouseLocation: 0,
    nowZoom: 0,
    urlParams: null,
    SVGObject: null,
    isShowChart: false,
  },
  mutations: {
    setToken(state, str) {
      state.token = str;
      Vue.ls.set("token", str);
    },
    setUrlParams(state, obj) {
      state.urlParams = obj;
    },
    setSVGObject(state, obj) {
      state.SVGObject = obj;
    },
    setMouseLocation(state, arr) {
      state.mouseLocation = arr;
    },
    setZoom(state, zoom) {
      state.nowZoom = zoom;
    },
    addLayer(state, obj) {
      state.layers.unshift(obj);
    },
    removeLayer(state, obj) {
      state.layers = state.layers.filter(function (item) {
        return item.layerId != obj.layerId;
      })
    },
    resetLayer(state, arr) {
      state.layers = arr.concat([])
    },
    setChartIsShow(state, bool) {
      state.isShowChart = bool
    }
  },
  actions: {
    addLayerControl(context, obj) {
      context.commit('addLayer', obj)
    },
    removeLayerControl(context, obj) {
      context.commit('removeLayer', obj)
    },
    resetLayerControl(context, arr) {
      context.commit('resetLayer', arr)
    },
  },
  modules: {
  }
})
