import {columns, users} from './StaticData'
import {isEmpty} from 'ramda'

const initState = {
  adminData: [],
};

const state = {
  ...initState
};

const getters = {
  adminData: (state) => state.adminData,
};

const mutations = {
  setAdminData: (state, updval) =>  state.adminData = updval,
  resetStore: (state) => {
    Object.entries(initState).forEach(([k,v]) => {
      state[k] = v
    })
  },
};

const actions = {
  uploadData: async ({commit}, historyData) => {
    try{

      /*
      
      Получаем список всех админов

      report = %{
        data:
          AuthenticationService.list_admins()
          |> Enum.map(&Map.put(&1, :fio, Event.user_fio(&1)))
          |> DynamicStructDestroyer.destroy(),
        columns: StaticData.columns(:list_admins) |> tablefy,
        height: "200px"
      }
      
      */
      console.log('historyData', historyData)
      const adminList = !isEmpty(users) ? users : []

      const report = {
        dataSource: adminList.data,
        columns: columns,
        height: "300px"
      }

      commit('setAdminData', report)
    } catch (err) {
      console.error(err)
    }
  },
  resetStore: ({commit}) => {
    commit('resetStore')
  }
};

export const store = {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
