import { generateId } from "@/lib/id" import type { Notification } from "@/lib/types" import { create } from "zustand" interface CreateNotificationInput { type: Notification["type"] title: string content: string link?: string } interface NotificationState { notifications: Notification[] addNotification: (input: CreateNotificationInput) => Notification markAsRead: (notificationId: string) => void markAllAsRead: () => void } export const useNotificationStore = create((set) => ({ notifications: [], addNotification: (input) => { const notification: Notification = { id: generateId("notif"), type: input.type, title: input.title, content: input.content, link: input.link, read: false, createdAt: new Date().toISOString(), } set((state) => ({ notifications: [notification, ...state.notifications], })) return notification }, markAsRead: (notificationId) => set((state) => ({ notifications: state.notifications.map((notification) => notification.id === notificationId ? { ...notification, read: true } : notification, ), })), markAllAsRead: () => set((state) => ({ notifications: state.notifications.map((notification) => ({ ...notification, read: true })), })), }))