import { create } from 'zustand'; import { api } from '../lib/api'; type NotificationLevel = 'all' | 'mentions' | 'none'; interface NotificationSettingsState { settings: Record; initialized: boolean; loaded: boolean; fetchSettings: () => Promise; setLevel: (channelId: string, level: NotificationLevel) => Promise; } export const useNotificationSettingsStore = create()((set) => ({ settings: {}, initialized: false, loaded: false, fetchSettings: async () => { try { const settings = await api.get>('/channels/me/notifications'); set({ settings, loaded: true, initialized: true }); } catch { set({ loaded: true, initialized: true }); } }, setLevel: async (channelId: string, level: NotificationLevel) => { await api.put(`/channels/${channelId}/notifications`, { level }); set((state) => ({ settings: { ...state.settings, [channelId]: level }, })); }, }));