const SET_PAGES = 'SET_PAGES';
const SET_AD = 'SET_AD';

const state = {
  loaded: false,
  data: undefined,
  ad: false,
};

const getters = {
  pages(state) {
    return state.data;
  },
};

const actions = {
  setPage({ commit }, pages) {
    console.log('setPage', pages);
    if (pages.main.adUrl) {
      commit(SET_AD, true);
    }
    commit(SET_PAGES, pages);
  },
};

const mutations = {
  [SET_PAGES](state, payload) {
    console.log('SET_PAGES', payload);
    state.loaded = true;
    state.data = payload;
  },
  [SET_AD](state, payload) {
    state.ad = payload;
  },
};

export default {
  state,
  getters,
  actions,
  mutations,
};
