/* ========================================================= SRZCyber — Store produits (localStorage) Les produits ajoutés dans admin.html sont lus par index.html et market.html via la même clé de stockage. ========================================================= */ const SRZ_STORE_KEY = 'srzcyber_products_v1'; const SrzStore = { getAll(){ try{ const raw = localStorage.getItem(SRZ_STORE_KEY); return raw ? JSON.parse(raw) : []; }catch(e){ console.error('SrzStore: lecture impossible', e); return []; } }, saveAll(products){ try{ localStorage.setItem(SRZ_STORE_KEY, JSON.stringify(products)); return true; }catch(e){ console.error('SrzStore: écriture impossible', e); return false; } }, add(product){ const products = this.getAll(); const item = { id: 'p_' + Date.now() + '_' + Math.random().toString(36).slice(2,8), title: product.title || 'Sans titre', description: product.description || '', link: product.link || '#', image: product.image || '', price: Number(product.price) || 0, createdAt: Date.now() }; products.unshift(item); this.saveAll(products); return item; }, update(id, patch){ const products = this.getAll(); const idx = products.findIndex(p => p.id === id); if(idx === -1) return null; products[idx] = { ...products[idx], ...patch }; this.saveAll(products); return products[idx]; }, remove(id){ const products = this.getAll().filter(p => p.id !== id); this.saveAll(products); } };