import {
  getData,
  advancedSearch,
} from "@/api/archiveUtilize/archivesRetrieval/fullTextSearch.js";
import { getButtonList } from "@/api/user";
import { message } from "@/utils/common";
const getDefaultState = () => {
  return {
    pagination: {
      pageSize: 10,
      pageNum: 1,
      total: 0,
    },
    loadingStatus: false,
    tableData: [],
    showButtons: {
      del: false,
      borrow: false,
      categoryBorrow: false,
    },
  };
};
const state = getDefaultState();
const mutations = {
  GET_DATA(state, data) {
    state.tableData = data.json;
    state.pagination.total = data.total;
    state.loadingStatus = false;
  },
  GET_BUTTON_LIST(state, data) {
    data.forEach((item) => {
      state.showButtons[item.key] = true;
    });
  },
};
const actions = {
  async getData({ commit, dispatch }, data) {
    await getData(data).then((res) => {
      try {
        commit("GET_DATA", res.body);
      } catch (err) {
        throw new Error(err);
      }
    });
  },
  async getHighData({ commit, dispatch }, data) {
    await advancedSearch(data).then((res) => {
      try {
        commit("GET_DATA", 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,
};
