import Vue from 'vue'
import Vuex from 'vuex'
import workFlow from './modules/workFlow.js'
import operationItem from './modules/operationItem.js'

Vue.use(Vuex)

const debug = process.env.NODE_ENV !== 'production'

const getters = {
  currentConnection: (state, getters) => {
    if (getters.operationItem.type !== 'connection') {
      return {}
    }

    const {sourceId, targetId} = getters.operationItem

    return getters.line(sourceId, targetId)
  },

  currentNode: (state, getters) => {
    // 节点类型： 开始: StartNode, 结束: EndNode, 节点: Node, 动作: ActionNode
    if (getters.operationItem.type !== 'StartNode' &&
      getters.operationItem.type !== 'EndNode' &&
      getters.operationItem.type !== 'Node' &&
      getters.operationItem.type !== 'ActionNode') {
      return {}
    }

    const {id} = getters.operationItem

    return getters.workflowNode(id)
  }
}

export default new Vuex.Store({
  getters,
  modules: {
    workFlow,
    operationItem
  },
  strict: debug
})
