import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state: { profile: any, messages: string[], drawer: boolean, snackbar: {visible: boolean, text: string } } = {
  profile: null,
  messages: [],
  drawer: true,
  snackbar: {
    visible: false,
    text: ''
  }
}

export default new Vuex.Store({
  state,
  mutations: {
    SET_DRAWER (state, payload) {
      state.drawer = payload
    },
    OPEN_SNACKBAR (state, text) {
      state.snackbar.text = text
      state.snackbar.visible = true
    },
    CLOSE_SNACKBAR (state) {
      state.snackbar.visible = false
    }
  },
  actions: {
  },
  modules: {
  },
  getters: {
    profile: (state) => state.profile || {},
    isMaster: (state) => !!state.profile?.master
  }
})
