import Carousel from './carousel.js';

const btechTimeTrackerEl = document.querySelector('.btech-time-tracker');
const workdeskEl = document.querySelector('.workdesk');
const cnaEl = document.querySelector('.btech-cna-charting');
const workroomEl = document.querySelector('.workroom-carousel');

new Carousel(btechTimeTrackerEl);
new Carousel(workdeskEl);
new Carousel(cnaEl);
new Carousel(workroomEl);

// Current year in footer
const currentYear = new Date().getFullYear();
document.querySelector('#year').innerHTML = currentYear;

// To-top button
const toTopButton = document.querySelector('#to-top-button');

const scrollFunction = () => {
  if (document.body.scrollTop > 400 || document.documentElement.scrollTop > 400) {
    toTopButton.style.display = 'block';
  } else {
    toTopButton.style.display = 'none';
  }
};

const topFunction = () => {
  document.body.scrollTop = 0; // For Safari
  document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
};

toTopButton.addEventListener('click', topFunction);

window.onscroll = () => {
  scrollFunction();
};
