// Simulação de estoque promocional
let remaining = 200;
document.getElementById('remaining').innerText = remaining;
document.getElementById('smallRemaining').innerText = remaining;
// Simula queda do estoque a cada clique de compra (apenas visual)
function startCheckout(){
document.getElementById('checkout-section').scrollIntoView({behavior:'smooth'});
}
function handleSubmit(e){
e.preventDefault();
const name = document.getElementById('name').value.trim();
const email = document.getElementById('email').value.trim();
const pack = (document.querySelector('input[name="pack"]:checked')||{}).value || 'ebook';
const bump = document.getElementById('bump').checked;
// calcular preço
let total = 0;
if(pack==='ebook') total = (remaining>0?9:27);
if(pack==='ebook_tree') total = 497;
if(pack==='ebook_5trees') total = 1997;
if(bump) total += 47;
// reduzir estoque promocional se aplicável
if(remaining>0 && pack==='ebook'){
remaining -= 1;
document.getElementById('remaining').innerText = remaining;
document.getElementById('smallRemaining').innerText = remaining;
}
// exibir simulação de checkout
const res = document.getElementById('checkoutResult');
res.style.display = 'block';
res.innerHTML = `
Obrigado, ${name}! Enviamos instruções para ${email}. Total: R$${total}. (Simulação)
`;
// aqui: substituir por integração com gateway
// Exemplo: enviar dados para seu backend que cria pagamento no PagSeguro/Stripe/Pagar.me
// após 'pagamento' abrir modal de upsell se aplicável
if(pack==='ebook'){
setTimeout(()=>{
// mostrar upsell suavemente
openUpsell();
},800);
}
}
// Upsell modal controls
const upsellModal = document.getElementById('upsellModal');
function openUpsell(){ upsellModal.classList.add('open'); upsellModal.setAttribute('aria-hidden','false'); }
function closeUpsell(){ upsellModal.classList.remove('open'); upsellModal.setAttribute('aria-hidden','true'); }
function acceptUpsell(){
closeUpsell();
// simula redirecionamento ao checkout para o premium
alert('Você será redirecionado para finalizar o pacote Premium (simulação).');
// aqui integrar com gateway
}
// footer year
document.getElementById('year').innerText = new Date().getFullYear();
// Accessibility: close modal on esc
document.addEventListener('keydown', function(e){ if(e.key === 'Escape'){ closeUpsell(); } });