import { defineStore } from 'pinia';

export const subTableStore = defineStore({
  id: 'subTable',
  state: () => ({
    tableDta: [],
    groupData: {},
    toSetGroupData: false,
  }),
  getters: {
    getTableData(state) {
      return state.tableDta;
    },
    getGroupData(state) {
      return state.groupData;
    },
    getToSetGroupData(state){
      return state.toSetGroupData;
    }
  },
  actions: {
    setTableData(data) {
      this.tableDta = data;
    },
    setToSetGroupData(){
      this.toSetGroupData = true
    },
    setSingleData(parentFileId, data) {
      this.tableDta.forEach((item, i) => {
        if (item.parentFileId == parentFileId) {
          item.child = data;
        }
      });
    },
    setGroupData(data) {
      for (const key2 in data) {
        if (data[key2] != undefined) {
          this.groupData[key2] = data[key2];
        }
      }
    },
    setOneGroupData (key,data){
      this.groupData[key] = data
      console.log(this.groupData)
    },
    clearGoupData() {
      this.groupData = {};
      this.toSetGroupData = false;
    },
  },
});
