import { defineStore } from 'pinia';
import Cookies from 'js-cookie';
import { setAccount, removeAccount } from "@/utils/auth";
import { ref } from 'vue';

export const useUserStore = defineStore("user", () => {
  const username = ref(Cookies.get('username') || '');
  
  async function  fetchUserInfo() {
    // Simulate API call
  }

  function setUserInfo(params: any) {
    setAccount({
      username: params.username,
      password: params.password,
      rememberMe: params.rememberMe ? "true" : "false",
    });
  }

  function clearUserInfo() {
    removeAccount();
  }

  return {
    username,
    fetchUserInfo,
    setUserInfo,
    clearUserInfo,
  }
});
