const banner = document.getElementById('full-banner');
const cdTime = banner?.querySelector('.cd-time');

const targetDate = new Date('Fri Sep 18 2020 10:30:00 GMT+0200 (Central European Summer Time)');


function countdownTimer() {
  if (!banner) return;
  
  const difference = +new Date(targetDate) - +new Date();
  let remaining = '';

  if (difference > 0) {
    const parts = {
      days: Math.floor(difference / (1000 * 60 * 60 * 24)),
      hours: Math.floor((difference / (1000 * 60 * 60)) % 24),
      minutes: Math.floor((difference / 1000 / 60) % 60),
      seconds: Math.floor((difference / 1000) % 60),
    };

    remaining = Object.keys(parts)
      .map((part) => {
        if (!parts[part]) return;
        return `${parts[part]} ${part}`;
      })
      .join(' ');

      cdTime.innerText = remaining;
  } else {
      banner.classList.add('live');
      banner.querySelector('h1').innerHTML = `ReclaimFutures is now LIVE <a href="/rf2020/watch" class="with-url-arrow">watch</a>`;
  }
}

export default countdownTimer;
