// Notification drawer open state + unread count. The drawer is mounted once
// in the default layout; the topbar bell button toggles it.

import { notifications as fixture } from '~/data/notifications'

const open = ref(false)
const items = ref(fixture)

export const useNotificationDrawer = () => {
  const unreadCount = computed(() => items.value.filter((n) => !n.read).length)

  return {
    open,
    items,
    unreadCount,
    show: () => {
      open.value = true
    },
    hide: () => {
      open.value = false
    },
    toggle: () => {
      open.value = !open.value
    },
    markAllRead: () => {
      items.value = items.value.map((n) => ({ ...n, read: true }))
    },
  }
}
