export { dsTeaserListVertical, dsTeaserListVerticalStory };

function dsTeaserListVertical(teaserListVerticalWrappers = []) {
  teaserListVerticalWrappers.forEach((wrapper) => {
    const teaserListGroupHeader = wrapper.querySelector('.ds-group-header--bottom-border');
    teaserListGroupHeader?.classList.remove('ds-group-header--bottom-border');

    const teaserListVerticalContentContainer = wrapper.querySelector('.ds-teaser-list-vertical__content');
    teaserListVerticalContentContainer.addEventListener('scroll', () => {
      const scrolledToTop = teaserListVerticalContentContainer.scrollTop === 0;
      teaserListGroupHeader.classList.toggle('ds-group-header--bottom-border', !scrolledToTop);
    });
  });
}

function dsTeaserListVerticalStory() {
  const teaserListVerticalWrappers = Array.from(document.getElementsByClassName('ds-teaser-list-vertical--flexible'));
  dsTeaserListVertical(teaserListVerticalWrappers);
}
