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

Vue.use(Vuex) //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: { //存放状态
		username: 'admin',
		token: 'c74d427b805beeb5501345f87f1a55af',
		fullScreen: false,
		
		// 场控地图页
		// mapReload: false, // 页面是否重载 true: 需恢复暂存数据 false: 无需恢复暂存数据
		mapPopupShow: false,
		mapControlRoute: true,
		mapControlPlayer: true,
		mapControlTooltip: true,
		mapControlTrail: true,
		mapSltMapId: 0, // 存储用户选择的地图ID
		mapSltActRoute: '', // 存储用户选择的活动路线信息 格式：活动ID-路线ID 例如：3-1 (0代表全部)
		holdTime: null, // 暂存时间 用于数据过期管理
		holdPlayersData: [{ // 暂存玩家数据 用于reload页面后重新恢复数据
			id: 0, // 玩家ID
			trailData: [], // 玩家轨迹信息（数据会追加并定时清理过期数据）
		}],
	},
	getters: {
		metadata: state => {
			return {
				token: state.token
			}
		}
	},
	mutations: {
		setUsername(state, username) {
            state.username = username
            console.log("[setUsername] state.username = " + username)
        },
		setToken(state, token) {
		    state.token = token
		    console.log("[setUsername] state.token = " + token)
		},
		setFullScreen(state, fullScreen) {
		    state.fullScreen = fullScreen
		    console.log("[setFullScreen] state.fullScreen = " + fullScreen)
		},
		
		// setMapReload(state, mapReload) {
		//     state.mapReload = mapReload
		//     console.log("[setMapReload] state.mapReload = " + mapReload)
		// },
		setMapPopupShow(state, mapPopupShow) {
		    state.mapPopupShow = mapPopupShow
		    console.log("[setMapPopupShow] state.mapPopupShow = " + mapPopupShow)
		},
		setMapControlRoute(state, mapControlRoute) {
		    state.mapControlRoute = mapControlRoute
		    console.log("[setMapControlRoute] state.mapControlRoute = " + mapControlRoute)
		},
		setMapControlPlayer(state, mapControlPlayer) {
		    state.mapControlPlayer = mapControlPlayer
		    console.log("[setMapControlPlayer] state.mapControlPlayer = " + mapControlPlayer)
		},
		setMapControlTooltip(state, mapControlTooltip) {
		    state.mapControlTooltip = mapControlTooltip
		    console.log("[setUsername] state.mapControlTooltip = " + mapControlTooltip)
		},
		setMapControlTrail(state, mapControlTrail) {
		    state.mapControlTrail = mapControlTrail
		    console.log("[setMapControlTrail] state.mapControlTrail = " + mapControlTrail)
		},
		setMapSltMapId(state, mapSltMapId) {
		    state.mapSltMapId = mapSltMapId
		    console.log("[setMapSltMapId] state.mapSltMapId = " + mapSltMapId)
		},
		setMapSltActRoute(state, mapSltActRoute) {
		    state.mapSltActRoute = mapSltActRoute
		    console.log("[setMapSltActRoute] state.mapSltActRoute = " + mapSltActRoute)
		},
		
		setHoldTime(state, holdTime) {
		    state.holdTime = holdTime
		    console.log("[setHoldTime] state.holdTime = " + holdTime)
		},
		pushHoldPlayersData(state, playerData) {
		    state.holdPlayersData.push(playerData)
		    console.log("[pushHoldPlayersData] state.holdPlayersData.push ", playerData)
		},
		clearHoldPlayersData(state) {
		    state.holdPlayersData.length = 0 // 清空数组
		    console.log("[clearHoldPlayersData] 清空 state.holdPlayersData")
		},
	}
})

export default store