import { defineStore, type StoreDefinition } from 'pinia'
import type { Notification } from '@/types'

export const useNotificationStore: StoreDefinition = defineStore('notifications', {
  state: () => ({
    notifications: [] as Notification[]
  }),
  getters: {
    getNotifications: (state: any) => state.notifications
  },
  actions: {
    addNotification(notification: Notification) {
      if (!notification.id) {
        notification.id = Math.random().toString(16)
      }
      this.notifications.push(notification)
    },
    removeNotification(id: string) {
      this.notifications = this.notifications.filter((notification: Notification) => notification.id !== id)
    }
  }
})
