/*
 * @Author: Badguy
 * @Date: 2022-05-17 15:35:35
 * @LastEditTime: 2022-05-17 17:44:00
 * @LastEditors: your name
 * @Description: 时区统一管理
 * have a nice day!
 */

const defaultTimeZone = 8
const savedTimeZone = sessionStorage.getItem('currentTimeZone')

const state = {
  currentTimeZone: Number(savedTimeZone ?? defaultTimeZone)
}

const mutations = {
  SET_TIME_ZONE(state, timeZone) {
    state.currentTimeZone = timeZone
    sessionStorage.setItem('currentTimeZone', timeZone)
  }
}

const actions = {
  setTimeZone({ commit }, timeZone) {
    commit('SET_TIME_ZONE', timeZone)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
