import { defineStore } from "pinia";
import { getToken, setToken, removeToken, getFirst, setFirst } from '../utils/auth'
import { login, getInfo, logout } from '../assets/api/user'


export const useUsersStore = defineStore('users', {
  state: () => {
    return {
      token: getToken(),
      first: getFirst(),
      avatar: '',
      introduction: '',
      id: '',
      name: '',
      order: 0,
      income: 0,
      roles: []
    }
  },
  getters: {

  },

  actions: {
    login({ commit }, userInfo) {
      console.log(userInfo)
      return new Promise((resolve, reject) => {
        login(userInfo).then(data => {
          commit('SET_TOKEN', data.token)
          setToken(data.token)
          resolve(data.super)
        }).catch(err => reject(err))
      })
    },
  }
})
