import { defineStore } from 'pinia'
import { api } from '../api'

export const useUserStore = defineStore('user', {
  state: () => ({
    profile: null
  }),
  getters: {
    role: (s) => s.profile?.role,
    loggedIn: (s) => !!s.profile
  },
  actions: {
    async fetchMe() {
      this.profile = await api.me()
    },
    async logout() {
      localStorage.removeItem('token')
      this.profile = null
    }
  }
})
