import { useCallback, useEffect, useState } from 'react';
import { getSegmentation } from '@reltio/mdm-sdk';
import { useSafePromise } from '../useSafePromise';
export var useSegmentationRequest = function (_a) {
    var filter = _a.filter;
    var _b = useState([]), segments = _b[0], setSegments = _b[1];
    var _c = useState(false), isLoading = _c[0], setIsLoading = _c[1];
    var safePromise = useSafePromise();
    var getSegments = useCallback(function () {
        setIsLoading(true);
        safePromise(getSegmentation({ filter: filter }))
            .then(setSegments)
            .catch(function (e) {
            console.warn('get segmentation error:', e);
            setSegments([]);
        })
            .finally(function () {
            setIsLoading(false);
        });
    }, [safePromise, filter]);
    useEffect(function () {
        getSegments();
    }, [getSegments]);
    return {
        segments: segments,
        isLoading: isLoading
    };
};
