import Vue from 'vue';
import Vuex from 'vuex';
import fa from "element-ui/src/locale/lang/fa";

Vue.use(Vuex);
/**
 * 设置全局访问的state对象
 store
 */
const state = {
	user_info: '', //用户信息
	sessionList: [],//会话列表
	offlineList: [],//离线列表
	current_session:[],//当前会话详情信息
	sessionType: 1,//选择列表状态默认未1(1是会话中，2是离线)
	data_num: 0,//定位当前会话，默认是0
	navState: 'TheCurrentSession',//导航状态
	session_name: '',//当前会话用户名
	session_message:'',//接收会话信息
	stateValue: '',//状态值
	is_init: false,//初始化,
	new_drawer: false, //显示消息中心
	session_user_info:{},//当前会话用户信息
}

/**
 * 实时监听state里面值的变法(最新变法)
 */
const getters = {
	get_user_info(state) {
		return state.user_info;
	},
	get_session(state) {
		return state.sessionList;
	},
	get_offline(state) {
		return state.offlineList;
	},
	get_current(state) {
		return state.current_session;
	},
	get_type(state) {
		return state.sessionType;
	},
	get_num(state) {
		return state.data_num;
	},
	get_navState(state) {
		return state.navState;
	},
	get_session_name(state) {
		return state.session_name;
	},
	get_session_message(state) {
		return state.session_message;
	},
	get_stateValue(state) {
		return state.stateValue;
	},
	get_is_init(state) {
		return state.is_init;
	},
    get_drawer(state) {
        return state.new_drawer;
	},
	get_session_user(state){
		return state.session_user_info;
	}
}
/**
 * 设置对外可调用的方法
 */
const mutations = {
	new_user_info(state, val) {
		state.user_info = val;
		//console.log(val);
	},
	new_session(state, val) {
		state.sessionList = val;
	},
	new_offline(state, val) {
		state.offlineList = val;
	},
	new_current(state, val) {
		state.current_session = val;
	},
	new_type(state, val) {
		state.sessionType = val;
	},
	new_num(state, val) {
		state.data_num = val;
	},
	new_navState(state, val) {
		state.navState = val;
	},
	new_session_name(state, val) {
		state.session_name = val;
	},
	new_session_message(state, val) {
		state.session_message = val;
	},
	new_stateValue(state, val) {
		state.stateValue = val;
	},
	new_is_init(state, val) {
		state.is_init = val;
	},
	new_drawer(state, val) {
		state.new_drawer = val;
	},
	new_session_user(state, val) {
		state.session_user_info = val;
	},
}

/**
 * 这里面的方法是用来异步触发mutations里面的方法
 */
const actions = {
	SET_USER(context, val) {
		context.commit('new_user_info', val);
	},
	SET_SESSION(context, val) {
		context.commit('new_session', val);
	},
	SET_OFFLINE(context, val) {
		context.commit('new_offline', val);
	},
	SET_CURRENT(context, val) {
		context.commit('new_current', val);
	},
	SET_TYPE(context, val) {
		context.commit('new_type', val);
	},
	SET_NUM(context, val) {
		context.commit('new_num', val);
	},
	SET_NAVSTATE(context, val) {
		context.commit('new_navState', val);
	},
	SET_SESSION_NAME(context, val) {
		context.commit('new_session_name', val);
	},
	SET_SESSION_MESSAGE(context, val) {
		context.commit('new_session_message', val);
	},
	SET_STATEVALUE(context, val) {
		context.commit('new_stateValue', val);
	},
	SET_IS_INIT(context, val) {
		context.commit('new_is_init', val);
	},
	SET_DRAWER(context, val) {
		context.commit('new_drawer', val);
	},
	SET_SESSSION_USER(context, val) {
		context.commit('new_session_user', val);
	}
}
const store = new Vuex.Store({
	state,
	getters,
	mutations,
	actions
});
export default store;
