import { defineStore } from 'pinia'

export const pkNoticeStore = defineStore('pkNoticeNum', {
  state: () => {
    return { data: { num: 0 } }
  },
  actions: {
    increment() {
      this.data.num++
    }
  }
})

export const pkTokenStore = defineStore('pkToken', {
  state: () => {
    return { token: '' }
  },
  actions: {
    setToken(token) {
      this.token = token
    }
  }
})

export const pkUserStore = defineStore('pkUser', {
  state: () => {
    return { user: {} }
  },
  actions: {
    setUser(user) {
      this.user = user
    }
  }
})

export const pkIMloginStore = defineStore('pkIMlogin', {
  state: () => {
    return { IMstate: false }
  },
  actions: {
    setIMstate(state) {
      this.IMstate = state
    }
  }
})

export const pkUnreadStore = defineStore('pkUnread', {
  state: () => {
    return { count: 0 }
  },
  actions: {
    setCount(count) {
      this.count = count
    },
    decrease(num = 1) {
      this.count = Math.max(0, this.count - num)
    },
    clear() {
      this.count = 0
    }
  }
})
