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

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
	},
}

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)
		}
	}
}

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