import { defineStore } from 'pinia';

export interface UserInfo {
  username: string;
  [key: string]: any;
}

export const useUserStore = defineStore('user', {
  state: () => ({
    token: localStorage.getItem('token') || '',
    userInfo: null as UserInfo | null,
  }),
  getters: {
    isLogin: (state) => !!state.token,
  },
  actions: {
    setToken(token: string) {
      this.token = token;
      localStorage.setItem('token', token);
    },
    setUserInfo(userInfo: UserInfo) {
      this.userInfo = userInfo;
    },
    reset() {
      this.token = '';
      this.userInfo = null;
      localStorage.removeItem('token');
    },
  },
}); 