import { defineStore } from 'pinia';
import { ref } from 'vue'

export const useUserStore = defineStore('user', () => {
	const userInfo = ref(null);
	const userId = ref(0);
	
	function setUserInfo(info) {
		userInfo.value = info;
		uni.setStorageSync('uInfo', JSON.stringify(info));
		userId.value = info.studentid
	}
	
	function getUserInfo() {
		const info = uni.getStorageSync('uInfo');
		return userInfo.value || (info ? JSON.parse(info) : null);
	}
	
	return { userInfo, userId, setUserInfo, getUserInfo };
})
