const billieEl = {
    modalId: '#billieLearnMoreModal',
    openLink: '.billie__link[data-target="#billieLearnMoreModal"]',
    scrollBody: '.modal-body.modal-box__body',
    content: '.modal-content.modal-box__content',
};

function resetBillieModalScroll($modal) {
    const bodyEl = $modal.find(billieEl.scrollBody)[0];
    if (bodyEl) bodyEl.scrollTop = 0;
    $modal.find(billieEl.content).attr('data-scroll-state', 'top');
}

export function initBillieModal() {
    const $modal = $(billieEl.modalId);
    if (!$modal.length) return;

    $(document).on('click', billieEl.openLink, function () {
        resetBillieModalScroll($modal);
    });

    $(document).on('shown.bs.modal', billieEl.modalId, function () {
        resetBillieModalScroll($modal);
        requestAnimationFrame(() => resetBillieModalScroll($modal));
        setTimeout(() => resetBillieModalScroll($modal), 30);
    });

    $(document).on('hidden.bs.modal', billieEl.modalId, function () {
        resetBillieModalScroll($modal);
    });
}
