import {
  getTree
} from "@/api/archives-management/fileManagement/notRecycleBin.js";
import { selectOpenControlByClassId } from "@/api/system-management/openControl"

  const getDefaultState = () => {
    return {
      treeData: [],
      tableLoading: false,
      loading: false,
      tableData: [],
    }
  }
  const state = getDefaultState()
  const mutations = {
    GET_TREE(state, data) {
      state.treeData = data.list
      state.loading = false
    },
    GET_DATA(state, data) {
      state.tableData = data.data
      state.tableLoading = false
    },
  }
  const actions = {
    async getTree({
      commit,
      dispatch
    }, data) {
      await getTree(data).then(res => {
        try {
          commit('GET_TREE', res.body)
        } catch (err) {
          throw new Error(err)
        }
      })
    },
    async getData({
      commit,
      dispatch
    }, data) {
      await selectOpenControlByClassId(data).then(res => {
        try {
          commit('GET_DATA', res.body)
        } catch (err) {
          throw new Error(err)
        }
      })
    },
  }
  export default {
    namespaced: true,
    state,
    mutations,
    actions
  }
  