import * as T from '../../utils/types'
import { MEMBER_AUTHORITY } from '@/store/utils/localStorageKeys'

export default {
  [T.SET_MEMBER_AUTORITY](state, payload) {
    state.memberAuthorityInitialized = true
    state.memberAuthority = payload.reduce((obj, permission) => {
      obj[permission.module.eshop_alias] = [...(obj[permission.module.eshop_alias] || []), permission.operation.name]

      return obj
    }, {})

    localStorage.setItem(MEMBER_AUTHORITY, JSON.stringify(state.memberAuthority))

    state.permissionRefreshTime = new Date().valueOf()
  },
}
