import { ref } from 'vue'
import { defineStore } from 'pinia'
import { getUnreadCount } from '@/api/message'

export const useMessageStore = defineStore('message', () => {
  const unreadCount = ref(0)

  const updateUnreadCount = async () => {
    try {
      const res = await getUnreadCount()
      if (res.success) {
        unreadCount.value = res.data
      }
    } catch (error) {
      console.error('获取未读消息数量失败', error)
    }
  }

  return { unreadCount, updateUnreadCount }
})
