import { defineStore } from 'pinia';
import Cookies from 'js-cookie';

const USERNAME_KEY = 'username';

export const useUserStore = defineStore('user', {
  state: () => ({
    username: Cookies.get(USERNAME_KEY) || null,
  }),
  actions: {
    async fetchUserInfo() {
      // Simulate API call
      const fetchedUsername = 'mock_user'; 
      this.username = fetchedUsername;
      Cookies.set(USERNAME_KEY, fetchedUsername);
    },
    clearUserInfo() {
      this.username = null;
      Cookies.remove(USERNAME_KEY);
    },
  },
});
