/* Cart is a single subscription slot, not a general-purpose multi-item cart: * these are recurring subscriptions to one product, so picking a different * tier replaces whatever was in the cart rather than stacking two recurring * charges. add()/remove() are still distinct actions per the spec. */ (function () { var STORAGE_KEY = 'militia_cart'; function readCart() { try { var raw = localStorage.getItem(STORAGE_KEY); return raw ? JSON.parse(raw) : null; } catch (e) { return null; } } function writeCart(item) { if (item) { localStorage.setItem(STORAGE_KEY, JSON.stringify(item)); } else { localStorage.removeItem(STORAGE_KEY); } updateBadge(); } function addPlan(planKey) { var cfg = window.MILITIA_CONFIG.plans[planKey]; if (!cfg) return; writeCart({ planKey: planKey, name: cfg.name, price: cfg.price, installs: cfg.installs }); } function removeItem() { writeCart(null); } function updateBadge() { var badge = document.getElementById('cartCountBadge'); if (!badge) return; var cart = readCart(); if (cart) { badge.textContent = '1'; badge.classList.remove('d-none'); } else { badge.classList.add('d-none'); } } window.MilitiaCart = { get: readCart, addPlan: addPlan, remove: removeItem, updateBadge: updateBadge }; })();