"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMarkers = void 0;
var react_1 = require("react");
var useSafePromise_1 = require("../useSafePromise");
var MdmModuleContext_1 = require("../../contexts/MdmModuleContext");
var helpers_1 = require("./helpers");
var resolveHelpers_1 = require("./resolveHelpers");
var useMarkers = function (entities) {
    var _a = (0, react_1.useState)([]), markers = _a[0], setMarkers = _a[1];
    var _b = (0, react_1.useState)(false), loading = _b[0], setLoading = _b[1];
    var safePromise = (0, useSafePromise_1.useSafePromise)();
    var metadata = (0, MdmModuleContext_1.useMdmMetadata)();
    var servicesPath = (0, MdmModuleContext_1.useMdmServicesPath)();
    (0, react_1.useEffect)(function () {
        setLoading(true);
        safePromise((0, resolveHelpers_1.resolveMarkers)({ metadata: metadata, servicesPath: servicesPath, entities: entities }))
            .then(function (markers) {
            setMarkers(markers.filter(helpers_1.filterWrongLat));
        })
            .catch(function () {
            setMarkers([]);
        })
            .finally(function () {
            setLoading(false);
        });
    }, [metadata, servicesPath, entities, resolveHelpers_1.resolveMarkers, safePromise]);
    return { markers: markers, loading: loading };
};
exports.useMarkers = useMarkers;
