import { useEffect, useState } from 'react';
import { useSafePromise } from '../useSafePromise';
import { useMdmMetadata, useMdmServicesPath } from '../../contexts/MdmModuleContext';
import { filterWrongLat } from './helpers';
import { resolveMarkers } from './resolveHelpers';
export var useMarkers = function (entities) {
    var _a = useState([]), markers = _a[0], setMarkers = _a[1];
    var _b = useState(false), loading = _b[0], setLoading = _b[1];
    var safePromise = useSafePromise();
    var metadata = useMdmMetadata();
    var servicesPath = useMdmServicesPath();
    useEffect(function () {
        setLoading(true);
        safePromise(resolveMarkers({ metadata: metadata, servicesPath: servicesPath, entities: entities }))
            .then(function (markers) {
            setMarkers(markers.filter(filterWrongLat));
        })
            .catch(function () {
            setMarkers([]);
        })
            .finally(function () {
            setLoading(false);
        });
    }, [metadata, servicesPath, entities, resolveMarkers, safePromise]);
    return { markers: markers, loading: loading };
};
