import { defineStore } from "pinia"
import { ref } from "vue"

export const useUserStore = defineStore('user', () => {

    const userInfo = ref(JSON.parse(localStorage.getItem('userInfo') || '{}'));

    const setUserInfo = (data) => {
        userInfo.value = data;
        localStorage.setItem('userInfo', JSON.stringify(data));
    }

    const token = ref(localStorage.getItem('token') || '');

    const setToken = (data) => {
        token.value = data;
        localStorage.setItem('token', data);
    }

    return {
        userInfo,
        token,
        setUserInfo,
        setToken
    }
})