
import { defineStore } from 'pinia';


export const flowStore = defineStore({
  id: 'flow',
  state: () => ({
    flowWfData: [],
  }),
  getters: {
    getWfData(state) {
      return state.flowWfData;
    },
   
  },
  actions: {
     // 获取单个节点的数据
     getWfDataNode(id){
      var currentIndex = (this.flowWfData || []).findIndex((element) => element.id === id);
      if(currentIndex == -1){
        return null
      }else{
        return this.flowWfData[currentIndex]
      }
    },
    // 添加单个节点的数据
    setWfDataNode(data) {
      let flowWfData = this.flowWfData
      var currentIndex = (flowWfData || []).findIndex((element) => element.id === data.id);
      if(currentIndex == -1){
        this.flowWfData.push(data)
      }
    },
    // 全覆盖，供更新和详情使用
    setWfDataAll(list){
      this.flowWfData=list
    },
    // 修改单个节点的某项数据
    updataWfDataNode(id,key,value){
      let flowWfData = this.flowWfData
      var currentIndex = (flowWfData || []).findIndex((element) => element.id === id);
      this.flowWfData[currentIndex][key] = value
    },
    deleteWfData(data) {
      let flowWfData = this.flowWfData
      var currentIndex = (flowWfData || []).findIndex((element) => element.id === data.id);
      this.flowWfData.splice(currentIndex,1)
    }
  },
});
