import { create } from 'zustand'; import AsyncStorage from '@react-native-async-storage/async-storage'; const STORAGE_KEY = '@rebreak/chat-backgrounds'; // Pro-Chat-Hintergrund (lokal, gerätegebunden). Default = 'clean' (Insta-Style, // solider Theme-BG ohne Muster). 'pattern' = der WhatsApp-artige SVG-Symbol-BG. export type ChatBgStyle = 'clean' | 'pattern'; export const DEFAULT_CHAT_BG: ChatBgStyle = 'clean'; type ChatBackgroundState = { // partnerId → Stil. Fehlt der Key → DEFAULT_CHAT_BG. backgrounds: Record; init: () => Promise; setBackground: (partnerId: string, style: ChatBgStyle) => Promise; }; export const useChatBackgroundStore = create((set, get) => ({ backgrounds: {}, init: async () => { try { const raw = await AsyncStorage.getItem(STORAGE_KEY); if (raw) set({ backgrounds: JSON.parse(raw) }); } catch { // non-fatal — Default-Clean greift } }, setBackground: async (partnerId, style) => { const next = { ...get().backgrounds, [partnerId]: style }; set({ backgrounds: next }); try { await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(next)); } catch { // non-fatal } }, }));