import { defineStore } from "pinia";
import router from "@/router";

export const useUserStore = defineStore<"user", { curExam: Exam }, any, any>(
  "user",
  {
    persist: [
      {
        storage: sessionStorage,
        paths: ["userInfo"],
      },
      {
        storage: localStorage,
        paths: ["curExam"],
      },
    ],
    state: () => ({
      userInfo: null,
      curExam: null,
    }),
    actions: {
      setUserInfo(info: any) {
        this.userInfo = info;
      },
      setCurExam(exam: Exam) {
        this.curExam = exam;
      },
      setState(data: any) {
        this.$patch(data);
      },
      resetUserInfo() {
        this.$reset();
      },
      async logout() {
        //todo 退出登录接口
        // await logout();
        this.setUserInfo(null);
        router.push({ name: "Login" });
        window.electronApi?.changeWinSize("small");
      },
    },
  }
);
