import {
  findList,
  getClassTreeByClassName,
  findColumnList
} from "@/api/system-management/archiveSettings"
import { getButtonList } from "@/api/user"
import {
  message
} from '@/utils/common'
const getDefaultState = () => {
  return {
    tableOne: [],
    loading: false,
    pagination: {
      pageSize: 10,
      pageNum: 1,
      total: 0,
    },
    tableTwo: [],
    loadingT: false,
    paginationT: {
      pageSize: 10,
      pageNum: 1,
      total: 0,
    },
    showButtons: {
      add: false,
      edit: false,
      del: false,
    },
  }
}
const state = getDefaultState()
const mutations = {
  GET_TABLE_ONE(state, data) {
    state.tableOne = data.list
    state.loading = false
    state.pagination.total = data.total
  },
  GET_TABLE_TWO(state, data) {
    state.tableTwo = data.list
    state.loadingT = false
    state.paginationT.total = data.total
  },
  GET_BUTTON_LIST(state, data) {
    data.forEach(item => {
      state.showButtons[item.key] = true
    })
  }
}
const actions = {
  async findList({
    commit,
    dispatch
  }, data) {
    await findList(data).then(res => {
      try {
        commit('GET_TABLE_ONE', res.body)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async findColumnList({
    commit,
    dispatch
  }, data) {
    await findColumnList(data).then(res => {
      try {
        commit('GET_TABLE_TWO', res.body)
      } catch (err) {
        throw new Error(err)
      }
    })
  },
  async getButtonList({
    commit
  }, params) {
    await getButtonList(params).then(res => {
      commit('GET_BUTTON_LIST', res.body.list)
    })
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
