// src/store/modules/dict.js
export default {
  namespaced: true,
  state: () => ({
    dict: []
  }),
  getters: {
    getDict: (state) => (_key) => {
      if (!_key) return null;
      const item = state.dict.find((item) => item.key === _key);
      return item ? item.value : null;
    }
  },
  actions: {
    setDict({ commit }, { key, value }) {
      commit('SET_DICT', { key, value });
    },
    removeDict({ commit }, key) {
      commit('REMOVE_DICT', key);
    },
    cleanDict({ commit }) {
      commit('CLEAN_DICT');
    }
  },
  mutations: {
    SET_DICT(state, { key, value }) {
      state.dict.push({ key, value });
    },
    REMOVE_DICT(state, key) {
      const index = state.dict.findIndex(item => item.key === key);
      if (index > -1) {
        state.dict.splice(index, 1);
      }
    },
    CLEAN_DICT(state) {
      state.dict = [];
    }
  }
};