// 引入localStorage
const state = {
  isAdmin: parseInt(localStorage.getItem("isAdmin")) || null,
};

const mutations = {
  setIsAdmin(state, isAdmin) {
    if (isAdmin === null) {
      state.isAdmin = null;
      localStorage.removeItem("isAdmin");
    } else {
      state.isAdmin = parseInt(isAdmin);
      localStorage.setItem("isAdmin", isAdmin.toString());
    }
  },
};

// 取
const getters = {
  getIsAdmin: (state) => {
    return state.isAdmin;
  },
};

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