import union from 'lodash/union'
import xor from 'lodash/xor'

export const state = {
  globallyHighlightedObjects: [] /**< {number[]} uuids */,

  inDebug: false /* process.env.NODE_ENV !== 'production' */
}

export const mutations = {
  // SET_NODE_HIGHLIGHT, UNSET_NODE_HIGHLIGHT used by: MergeModal, CheckboxTable, CheckboxTableNodes
  SET_GLOBAL_HIGHLIGHTS(state, uuids) {
    state.globallyHighlightedObjects = union(state.globallyHighlightedObjects, uuids)
  },
  UNSET_GLOBAL_HIGHLIGHTS(state, uuids) {
    state.globallyHighlightedObjects = xor(state.globallyHighlightedObjects, uuids)
  },
  // CLEAR_NODE_HIGHLIGHT used by: CheckboxTable, CheckboxTableNodes
  CLEAR_GLOBAL_HIGHLIGHTS(state) {
    state.globallyHighlightedObjects = []
  },

  SET_DEBUG(state, bool) {
    state.inDebug = bool
  }
}

export const actions = {
  activateDebug({ commit }) {
    commit('SET_DEBUG', true)
  },
  deactivateDebug({ commit }) {
    commit('SET_DEBUG', false)
  },

  // used by: MergeModal
  stopHighlighting({ commit }) {
    commit('CLEAR_NODE_HIGHLIGHT')
    commit('CLEAR_LINK_HIGHLIGHT')
  }
}

export const getters = {
  isObjectGloballyHighlighted: state => uuid => state.globallyHighlightedObjects.includes(uuid),
  getGloballyHighlightedObjects: state => state.globallyHighlightedObjects
}
