import { listNotifications } from "@/lib/api/notifications" import type { Notification } from "@/lib/types" import { create } from "zustand" interface NotificationState { notifications: Notification[] loading: boolean fetchNotifications: () => Promise setNotifications: (notifications: Notification[]) => void markAllRead: () => void invalidate: () => void } export const useNotificationStore = create((set) => ({ notifications: [], loading: false, fetchNotifications: async () => { set({ loading: true }) try { const items = await listNotifications({ offset: 0, limit: 50 }) set({ notifications: items, loading: false }) } catch { set({ loading: false }) } }, setNotifications: (notifications) => set({ notifications }), markAllRead: () => set((state) => ({ notifications: state.notifications.map((notification) => notification.read ? notification : { ...notification, read: true }, ), })), invalidate: () => { set({ notifications: [] }) }, }))