const getDefaultState = (key) => {
  const state = {
    mini: false,
    viewPage: 'Home',
    coding: true
  }
  return state[key] || state
}
const state = getDefaultState()

const mutations = {
  SET_MINI (state, payload) {
    state.mini = payload
  },
  SET_CODING (state, payload) {
    state.coding = payload
  },
  SET_VIEWPAGE (state, payload) {
    state.viewPage = payload
  }
}

const actions = {
  setMini ({ commit }, payload) {
    commit('SET_MINI', payload)
  },
  setCoding ({ commit }, payload) {
    commit('SET_CODING', payload)
  },
  setViewPage ({ commit }, payload) {
    commit('SET_VIEWPAGE', payload)
    commit('local/SET_VIEWPAGE', payload, { root: true })
  }
}

const getters = {
  mini: (state) => state.mini,
  coding: (state) => state.coding,
  viewPage: (state, _, rootState) => rootState.local.viewPage || state.viewPage
}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters
}
