import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect } from 'react';
import { http } from '@selfcommunity/api-services';
import LazyLoad from 'react-lazyload';
import { MIN_PRELOAD_OFFSET_VIEWPORT } from '../../constants/LazyLoad';
const MarkRead = (props) => {
    // PROPS
    const { endpoint, params = {}, callback, data = null } = props;
    /**
     * Perform request
     */
    const performRequest = () => {
        http
            .request({
            url: endpoint.url(params),
            method: endpoint.method,
            data
        })
            .then((res) => {
            callback && callback(res);
        })
            .catch(() => null);
    };
    useEffect(() => {
        let _t;
        if (endpoint) {
            _t = setTimeout(performRequest);
            return () => {
                _t && clearTimeout(_t);
            };
        }
    }, []);
    return null;
};
export default (props) => {
    return (_jsx(LazyLoad, Object.assign({ once: true, offset: MIN_PRELOAD_OFFSET_VIEWPORT }, { children: _jsx(MarkRead, Object.assign({}, props)) })));
};
