import {pages} from './StaticData'

const initState = {
  pages: pages,

  activePath: '/',
  selectedPage: pages[0],
};

const state = {
  ...initState
};

const getters = {
  pages: (state) => state.pages,
  activePath: (state) => state.activePath,
  selectedPage: (state) => state.selectedPage,
};

const mutations = {
  setPath: (state, updval) =>  state.activePath = updval,
  setPage: (state, updval) =>  state.selectedPage = updval,
  resetStore: (state) => {
    Object.entries(initState).forEach(([k,v]) => {
      state[k] = v
    })
  },
};

const actions = {
  uploadData: async ({commit}, path) => {
    try{
      switch(path) {
      case '/finder_packs':
        commit('setPage', pages[1])
        break
      case '/add_users':
        commit('setPage', pages[2])
        break
      default:
        commit('setPage', pages[0])
        break
      }
      
    } catch(err) {
      console.log(err)
    }
  },
  resetStore: ({commit}) => {
    commit('resetStore')
  }
};

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