import { getLocalStorage, removeLocalStorage } from '@/utils/storage'

const user = {
  state: {
    mwxtoken: getLocalStorage('mwxtoken') || '',
    mwxidntf: getLocalStorage('mwxidntf') || '',
    mwxuser: JSON.parse(getLocalStorage('mwxuser')) || {},
    mwxrole: getLocalStorage('mwxrole') || '',
    mwxorg: getLocalStorage('mwxorg') || ''
  },

  mutations: {
    setmwxtoken: (state, payload) => {
      state.mwxtoken = payload
    },
    setmwxidntf: (state, payload) => {
      state.mwxidntf = payload
    },
    setmwxuser: (state, payload) => {
      state.mwxuser = payload
    },
    setmwxrole: (state, payload) => {
      state.mwxrole = payload
    },
    setmwxorg: (state, payload) => {
      state.mwxorg = payload
    }
  },
  actions: {
    login({ commit, state }, data) {
      return new Promise((resolve, reject) => {

      })
    },
    logout({ commit, state }) {
      return new Promise((resolve, reject) => {

      })
    },
    clear({ commit, state }) {
      return new Promise((resolve, reject) => {
        removeLocalStorage('mwxtoken')
        removeLocalStorage('mwxuser')
        removeLocalStorage('mwxidntf')
        removeLocalStorage('mwxorg')
        removeLocalStorage('mwxrole')
        removeLocalStorage('location_pointer')
        commit('setmwxtoken')
        commit('setmwxidntf')
        commit('setmwxuser')
        commit('setmwxrole')
        commit('setmwxorg')
        resolve()
      })
    }
  }
}

export default user
