import { useEffect } from 'react';
export const useUnreadPolling = (fetchUnreadCount, intervalMs = 5000, enabled = true) => {
    useEffect(() => {
        if (!enabled)
            return;
        let intervalId = null;
        const start = () => {
            if (!intervalId) {
                fetchUnreadCount();
                intervalId = setInterval(fetchUnreadCount, intervalMs);
            }
        };
        const stop = () => {
            if (intervalId) {
                clearInterval(intervalId);
                intervalId = null;
            }
        };
        const onVis = () => {
            if (document.visibilityState === 'visible')
                start();
            else
                stop();
        };
        onVis();
        document.addEventListener('visibilitychange', onVis);
        return () => {
            stop();
            document.removeEventListener('visibilitychange', onVis);
        };
    }, [fetchUnreadCount, intervalMs, enabled]);
};
//# sourceMappingURL=useUnreadPolling.js.map