"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const react_use_1 = require("react-use");
const useLogic = ({ id, onDelete, onViewNotification, isUnread, }) => {
    const ref = (0, react_1.useRef)(null);
    const entry = (0, react_use_1.useIntersection)(ref, {
        root: null,
        threshold: 0.95,
    });
    const handleDelete = () => {
        if (onDelete) {
            onDelete(id);
        }
    };
    (0, react_1.useEffect)(() => {
        if (onViewNotification && isUnread && entry?.isIntersecting) {
            onViewNotification(id);
        }
    }, [onViewNotification, entry?.isIntersecting, isUnread, id]);
    return {
        ref,
        handleDelete,
    };
};
exports.useLogic = useLogic;
