/* Site DTF — the order progress bar, the product card prices and the phone total bar. This file only reads the page's state (which panels are open, the cart total, the checkout status); it never changes an order, a price or a file, so the flow in the other site-*.js files behaves exactly as before. */ (function(){ // Card prices come from the same table the checkout uses, so they cannot drift. document.querySelectorAll('[data-de]').forEach(el=>{ el.textContent=rs(pisoEscada(el.dataset.de)); }); document.querySelectorAll('[data-ate]').forEach(el=>{ el.textContent=rs(TABELA[el.dataset.ate]); }); const passos=$('passos'), barra=$('barraM'); // The store header is sticky; the progress bar and the side panels sit below it. function alturas(){ const topo=document.querySelector('.topo')?.offsetHeight||0; document.documentElement.style.setProperty('--topo',topo+'px'); document.documentElement.style.setProperty('--topo-passos',(topo+(passos.hidden?0:passos.offsetHeight)+16)+'px'); } const foco=$('foco'), carr=$('carr'), status=$('checkoutStatus'), acoes=$('checkoutActions'); function naTela(el){ const r=el.getBoundingClientRect(); return r.top < innerHeight*0.55 && r.bottom > innerHeight*0.2; } function etapa(){ // Once the cart is sent, the quote, the payment and the order live in the // checkout status: that is the payment step. if((status.textContent||'').trim() || acoes.children.length) return 3; if(carr.classList.contains('on') && (naTela(carr) || !foco.classList.contains('on'))) return 2; return 1; } let pendente=false; function pinta(){ pendente=false; const ativo=foco.classList.contains('on') || carr.classList.contains('on') || (status.textContent||'').trim(); passos.hidden=!ativo; alturas(); if(ativo){ const atual=etapa(); passos.querySelectorAll('[data-passo]').forEach(a=>{ const n=Number(a.dataset.passo); a.classList.toggle('atual',n===atual); a.classList.toggle('feito',na.addEventListener('click',e=>{ const destino=document.querySelector(a.getAttribute('href')); if(!destino || destino.offsetParent===null){ e.preventDefault(); return; } e.preventDefault(); destino.scrollIntoView({behavior:'smooth',block:'start'}); })); $('barraMBtn').addEventListener('click',e=>{ e.preventDefault(); carr.scrollIntoView({behavior:'smooth',block:'start'}); }); pinta(); })();