import { useCallback, useEffect, useState } from 'react';
export function useIntersection(element, rootMargin) {
    const [isVisible, setState] = useState(false);
    useEffect(()=>{
        const observer = new IntersectionObserver(([entry])=>{
            setState(entry?.isIntersecting ?? false);
        }, {
            rootMargin
        });
        element && observer.observe(element);
        return ()=>element && observer.unobserve(element);
    }, [
        element,
        rootMargin
    ]);
    return isVisible;
}
export function useCountChildren() {
    const countChildren = useCallback((children)=>{
        let total = 0;
        children.forEach((child)=>{
            total += child.count;
            total += child.children ? countChildren(child.children) : 0;
        });
        return total;
    }, []);
    return countChildren;
}
