"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const api_services_1 = require("@selfcommunity/api-services");
const react_lazyload_1 = tslib_1.__importDefault(require("react-lazyload"));
const LazyLoad_1 = require("../../constants/LazyLoad");
const MarkRead = (props) => {
    // PROPS
    const { endpoint, params = {}, callback, data = null } = props;
    /**
     * Perform request
     */
    const performRequest = () => {
        api_services_1.http
            .request({
            url: endpoint.url(params),
            method: endpoint.method,
            data
        })
            .then((res) => {
            callback && callback(res);
        })
            .catch(() => null);
    };
    (0, react_1.useEffect)(() => {
        let _t;
        if (endpoint) {
            _t = setTimeout(performRequest);
            return () => {
                _t && clearTimeout(_t);
            };
        }
    }, []);
    return null;
};
exports.default = (props) => {
    return ((0, jsx_runtime_1.jsx)(react_lazyload_1.default, Object.assign({ once: true, offset: LazyLoad_1.MIN_PRELOAD_OFFSET_VIEWPORT }, { children: (0, jsx_runtime_1.jsx)(MarkRead, Object.assign({}, props)) })));
};
