import Vue from 'vue'
import Vuex from 'vuex'
import classMgmt from './module/classMgmt'
import courseMgmt from './module/courseMgmt'
import talMgmt from './module/talMgmt'
import authorization from './module/authorization'
import totalAnalysis from './module/totalAnalysis'
import schoolBaseInfo from './module/schoolBaseInfo'
import user from './module/user'
import config from './module/config'
import teachers from './module/teachers'
import studentWeb from './module/studentWeb'
import scboard from './module/scboard'
import serviceDriveAuth from './module/serviceDriveAuth'
import GLOBAL from '@/static/Global.js'
import spaceAuth from './module/spaceAuth'
import studentAclassOneAuth from './module/studentAclassOneAuth'


Vue.use(Vuex)

// TYPES
const MAIN_SET_COUNTER = 'MAIN_SET_COUNTER'

// MUTATIONS
const mutations = {
    [MAIN_SET_COUNTER](state, obj) {
        state.counter = obj.counter
    },
    setPrivateSas(state, obj) {
        state.privateSas = obj
    },
    setSchoolSas(state, obj) {
        state.schoolSas = obj
    },
    setUserInfo(state, obj) {
        obj.schoolCode = obj.schoolCode || GLOBAL.DEFAULT_SCHOOL_CODE
        obj.hasSchool = obj.schoolCode !== GLOBAL.DEFAULT_SCHOOL_CODE
		state.userInfo = obj
	},
	setSchoolCode(state,obj){
		state.userInfo.schoolCode = obj || GLOBAL.DEFAULT_SCHOOL_CODE
		state.userInfo.hasSchool = obj !== GLOBAL.DEFAULT_SCHOOL_CODE
	}
}

// ACTIONS
const actions = ({
    setCounter({ commit }, obj) {
        commit(MAIN_SET_COUNTER, obj)
    }
})

const getters = {
    radarData: state => state.totalAnalysis.radarData
}

export default new Vuex.Store({
    mutations,
    actions,
    getters,
    state: {
        userInfo: {
            TEAMModelId: '',
            name: '',
            schoolCode: '',
			hasSchool:false
        }
    },
    modules: {
        classMgmt,
        talMgmt,
        authorization,
        totalAnalysis,
        schoolBaseInfo,
        courseMgmt,
        user,
        config,
        teachers,
        studentWeb,
        scboard,
        serviceDriveAuth,
        spaceAuth,
        studentAclassOneAuth
    }
})
