(() => { const choices = [...document.querySelectorAll('[data-billing]')]; if (!choices.length) return; const format = value => new Intl.NumberFormat('ru-RU', { maximumFractionDigits: 2 }).format(value); let period = 'month'; try { if (JSON.parse(localStorage.getItem('mangabom.billing')) === 'year') period = 'year'; } catch {} const price = monthly => period === 'year' ? monthly * 12 * 83 / 100 : monthly; function apply() { choices.forEach(button => button.setAttribute('aria-pressed', String(button.dataset.billing === period))); document.querySelectorAll('[data-plan-price]').forEach(label => label.textContent = format(price(Number(label.dataset.planPrice)))); document.querySelectorAll('[data-plan-period]').forEach(label => label.textContent = period === 'year' ? 'в год' : 'в месяц'); document.querySelector('#billing-note').textContent = period === 'year' ? 'Оплата за год целиком. Скидка 17% уже включена.' : 'Цены указаны за месяц.'; document.querySelector('#plan-status').textContent = ''; } choices.forEach(button => button.addEventListener('click', () => { period = button.dataset.billing; try { localStorage.setItem('mangabom.billing', JSON.stringify(period)); } catch {} apply(); })); document.querySelectorAll('[data-plan]').forEach(button => button.addEventListener('click', () => { document.querySelector('#plan-status').textContent = 'Выбран ' + button.dataset.plan + ' — ' + format(price(Number(button.dataset.monthly))) + ' ₽ ' + (period === 'year' ? 'в год.' : 'в месяц.') + ' Оформление подписки пока недоступно.'; })); apply(); })();