export function initObserver(dotNetHelper, containerSelector, itemSelector) {
    const options = {
        root: null,
        rootMargin: '0px',
        threshold: 0.6 // 60% of the block must be visible
    };

    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                const id = entry.target.id;
                const content = entry.target.innerText;
                dotNetHelper.invokeMethodAsync('HandleBlockReached', id, content);
            }
        });
    }, options);

    const items = document.querySelectorAll(itemSelector);
    items.forEach(item => observer.observe(item));

    return observer;
}
