import { useEffect, useRef } from 'react';
import { useIntersection } from 'react-use';
export const useLogic = ({ id, onDelete, onViewNotification, isUnread, }) => {
    const ref = useRef(null);
    const entry = useIntersection(ref, {
        root: null,
        threshold: 0.95,
    });
    const handleDelete = () => {
        if (onDelete) {
            onDelete(id);
        }
    };
    useEffect(() => {
        if (onViewNotification && isUnread && entry?.isIntersecting) {
            onViewNotification(id);
        }
    }, [onViewNotification, entry?.isIntersecting, isUnread, id]);
    return {
        ref,
        handleDelete,
    };
};
