import { defineStore } from 'pinia';
import { ref } from 'vue'
import { login, logout } from '@/api/common.js'
import { useUserStore } from '@/store/user.js'

export const useSystemStore = defineStore('system', () => {
	const userStore = useUserStore()
	let appInfo = ref({})
	
	function setAppInfo (info) {
		appInfo.value = info;
	}
	
	function Login(params) {
		return new Promise((resolve, reject) => {
			login(params).then(res => {
				userStore.setUserInfo(res);
				resolve(res)
			}).catch(error => {
				console.log('登录失败：', error)
				reject(error)
			})
		})
	}
	
	function Logout() {
		return logout().then(res => {
			return res;
		})
	}
	
	return { Login, Logout, appInfo, setAppInfo }
})