import { signal } from '@preact/signals';
import { setRoute, route } from './store.js';
export const activeChapter = signal(1);
export function observeChapter(el, chapter) {
    const io = new IntersectionObserver((entries) => {
        for (const e of entries) {
            if (e.isIntersecting && e.intersectionRatio > 0.4) {
                activeChapter.value = chapter;
                if (route.value.chapter !== chapter) {
                    setRoute({ ...route.value, chapter }, true);
                }
            }
        }
    }, { threshold: [0.4, 0.6] });
    io.observe(el);
    return () => io.disconnect();
}
