import { defineStore } from "pinia";
import type { User } from "@renderer/types/user";
import { ref } from "vue";

export const useUserStore = defineStore(
    "user",
    () => {
        const user = ref<User | null>(null);
        const token = ref<string>("");

        function setUserInfo(userInfo: User) {
            user.value = userInfo;
        }

        function setToken(newToken: string) {
            token.value = newToken;
            // 通知主进程保存 token
            // window.electron.ipcRenderer.send("set-token", newToken);
        }

        return {
            user,
            token,
            setUserInfo,
            setToken,
        };
    },
    {
        persist: true,
    },
);
