// stores/useNotificationStore.js
import { create } from 'zustand';

export const useNotificationStore = create((set) => ({
    notifications: [],

    setNotifications: (notifications) => set({ notifications }),

    addNotification: (notification) =>
        set((state) => {
            const exists = state.notifications.some(n => n.id === notification.id);
            return {
                notifications: exists
                    ? state.notifications
                    : [...state.notifications, notification],
            };
        }),

    markAsRead: (notificationIds) =>
        set((state) => ({
            notifications: state.notifications.map(n =>
                notificationIds.includes(n.id) ? { ...n, read: true } : n
            ),
        })),

    clearNotifications: () => set({ notifications: [] }),
}));
