const app = {
  state: {
    loading: true,
    device: 'desktop',
    locale: 'zh-cn'
  },
  mutations: {
    SET_LOCALE: (state, locale) => {
      state.locale = locale
    },
    HIDE_LOADING: (state) => {
      state.loading = false
    },
    GET_DATA: (state, name) => {
      const item = JSON.parse(JSON.stringify(name))
      if (state[item]) {
        return JSON.parse(JSON.stringify(state[item]))
      }
    },
    SET_DATA: (state, res) => {
      const item = JSON.parse(JSON.stringify(res))
      if (item.name && !state[item.name]) {
        state[item.name] = ''
      }
      state[item.name] = JSON.parse(JSON.stringify(item.value))
    },
    DELETE_DATA: (state, res) => {
      if (res.name && state[res.name]) {
        delete state[res.name]
      }
    }
  },
  actions: {
    showLoading: ({ commit }) => {
      commit('SHOW_LOADING')
    },
    hideLoading: ({ commit }) => {
      commit('HIDE_LOADING')
    },
    getData: ({ commit }, data) => {
      commit('GET_DATA', data)
    },
    setData: ({ commit }, data) => {
      commit('SET_DATA', data)
    },
    deleteData: ({ commit }, data) => {
      commit('DELETE_DATA', data)
    }
  }
}

export default app
