function handleScrollButonDisplay() {
  const pageScroller = document.querySelector('#page-scroller');

  if (
    document.body.scrollTop > window.innerHeight / 2 ||
    document.documentElement.scrollTop > window.innerHeight / 2
  ) {
    pageScroller.removeAttribute('hidden');
  } else {
    pageScroller.setAttribute('hidden', '');
  }
}
function scrollTop() {
  window.scrollTo({
    top: 0,
    behavior: 'smooth',
  });
}
function scrollToFilters() {
  const filters = document.querySelector('.filters-toolbar');
  filters.scrollIntoView({
    behavior: 'smooth',
  });
}

export default function pageScrollerInit() {
  const pageScroller = document.querySelector('#page-scroller');
  if (!pageScroller) return;
  window.addEventListener('scroll', handleScrollButonDisplay);

  const scrollTopBtn = document.querySelector('#scroller-top');
  if (!scrollTopBtn) return;
  scrollTopBtn.addEventListener('click', scrollTop);

  const scrollerFilterBtn = document.querySelector('#scroller-filter');
  if (!scrollerFilterBtn) return;
  scrollerFilterBtn.addEventListener('click', scrollToFilters);
}
