const state = {
	model: '',
	safeArea: true,
    isIphoneX: '',
	systemInfo: {},
    isIphone: true,
}

const mutations = {
	SET_SYSTEM_INFO: (state, info) => {
		state.systemInfo = info
	},
	SET_MODEL: (state, model) => {
		console.log('model', model)
		state.model = model
	},
	SET_SAFE_AREA: (state, safeArea) => {
		console.log('safeArea', safeArea)
		state.safeArea = safeArea
	},
    SET_CHANGE_VAR: (state, isIphoneX) => {
        state.isIphoneX = isIphoneX
    },
    SET_IS_IPHONE: (state, isIphone) => {
        state.isIphone = isIphone
    },
}

const actions = {
	initDevice({ commit }) {
		const systemInfo = uni.getSystemInfoSync()
		commit('SET_SYSTEM_INFO', systemInfo)
		const model = systemInfo.model.toLowerCase().trim()
		commit('SET_MODEL', model)
		const reg = /^iphone\s?[4|5|6|7|8]{1}/gi
		if (reg.test(model) || model.indexOf('iphone') === -1) {
			commit('SET_SAFE_AREA', false)
		}
	},
    setVariableFun: function(context, vData) {
        context.commit('SET_CHANGE_VAR', vData)
    },
    setIsIphoneFun: function(context, vData) {
        context.commit('SET_IS_IPHONE', vData)
    },
}

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