export const TARGET_2050 = Date.parse('2050-01-01T00:00:00-03:00'); export function remainingTime(now, target = TARGET_2050) { const total = Math.max(0, Math.ceil((target - now) / 1000)); return { days: Math.floor(total / 86400), hours: Math.floor(total / 3600) % 24, minutes: Math.floor(total / 60) % 60, seconds: total % 60, complete: total === 0, }; } if (typeof document !== 'undefined') { const clock = document.querySelector('[data-countdown]'); if (clock) { const fields = [...clock.querySelectorAll('[data-unit]')]; const indicator = document.querySelector('[data-countdown-status]'); const yearLabel = document.querySelector('[data-current-year]'); let interval; function render() { const now = Date.now(); const remaining = remainingTime(now); for (const field of fields) { const value = remaining[field.dataset.unit]; const text = field.dataset.unit === 'days' ? value.toLocaleString('pt-BR') : String(value).padStart(2, '0'); if (field.textContent !== text) field.textContent = text; } if (yearLabel) yearLabel.textContent = new Intl.DateTimeFormat('pt-BR', { year: 'numeric', timeZone: 'America/Sao_Paulo', }).format(now) + ' / AGORA'; indicator.textContent = remaining.complete ? '2050 COMEƇA AGORA' : 'CONTAGEM REGRESSIVA EM TEMPO REAL'; if (remaining.complete) clearInterval(interval); return remaining.complete; } function resume() { clearInterval(interval); const complete = render(); if (!document.hidden && !complete) interval = setInterval(render, 1000); } document.addEventListener('visibilitychange', resume); resume(); } }