// ST-1105: Zustand store voor het Claude vraag-antwoord-kanaal (M11). // // Houdt de huidige set van **open** vragen voor de ingelogde gebruiker bij — // gevoed door: // - Initial-state-event van /api/realtime/notifications (init) // - Realtime SSE-events op scrum4me_changes (upsert/remove) // - Server Action answerQuestion (optimistic remove via removeOptimistic) // // Eenvoudiger dan solo-store: geen drag-and-drop, geen view-transitions, geen // pending-ops om optimistic-echo te onderdrukken — antwoorden zijn discrete // acties en de stream kan met dubbele update-events leven. import { create } from 'zustand' export interface NotificationQuestion { id: string product_id: string story_id: string task_id: string | null story_code: string | null story_title: string assignee_id: string | null question: string options: string[] | null created_at: string expires_at: string } interface NotificationsState { questions: NotificationQuestion[] init: (qs: NotificationQuestion[]) => void upsert: (q: NotificationQuestion) => void remove: (id: string) => void openCount: () => number forYouCount: (userId: string | null) => number } export const useNotificationsStore = create((set, get) => ({ questions: [], init: (qs) => set({ questions: qs }), upsert: (q) => set((state) => { const idx = state.questions.findIndex((x) => x.id === q.id) if (idx === -1) return { questions: [q, ...state.questions] } const next = state.questions.slice() next[idx] = q return { questions: next } }), remove: (id) => set((state) => ({ questions: state.questions.filter((q) => q.id !== id) })), openCount: () => get().questions.length, forYouCount: (userId) => { if (!userId) return 0 return get().questions.filter((q) => q.assignee_id === userId).length }, }))