import {
  lifeDataTopBtns,
} from '../assets/lifeData'
/**
 *  数据初始化
 */
const state = {
  lastCheckedTree:sessionStorage.getItem('lastCheckedTree'),
  lifeDataTopBtns:lifeDataTopBtns,
  treeId: sessionStorage.getItem('treeId'),
  dataId: sessionStorage.getItem('dataId'),
  settingId: sessionStorage.getItem('settingId'),
  wbId: sessionStorage.getItem('wbId'),
  analysisName: undefined,
  isAnalysis:false, // 是否分析
  whichTree:sessionStorage.getItem('whichTree'),
  hasProb:true,
  // treeDataId:false, // 树dataId

}

const mutations = {
  SET: (state, { key, value }) => {
    if (state.hasOwnProperty(key)) {
      if([
        'lastCheckedTree',
        'treeId',
        'dataId',
        'settingId',
        'wbId',
        'isAnalysis',
        'whichTree',
      ].indexOf(key) !== -1
      ) {
        sessionStorage.setItem(key, value)
      }
      state[key] = value
    }
  }
}

const actions = {
  set({ commit }, data) {
    commit('SET', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
