"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSegmentationRequest = void 0;
var react_1 = require("react");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var useSafePromise_1 = require("../useSafePromise");
var useSegmentationRequest = function (_a) {
    var filter = _a.filter;
    var _b = (0, react_1.useState)([]), segments = _b[0], setSegments = _b[1];
    var _c = (0, react_1.useState)(false), isLoading = _c[0], setIsLoading = _c[1];
    var safePromise = (0, useSafePromise_1.useSafePromise)();
    var getSegments = (0, react_1.useCallback)(function () {
        setIsLoading(true);
        safePromise((0, mdm_sdk_1.getSegmentation)({ filter: filter }))
            .then(setSegments)
            .catch(function (e) {
            console.warn('get segmentation error:', e);
            setSegments([]);
        })
            .finally(function () {
            setIsLoading(false);
        });
    }, [safePromise, filter]);
    (0, react_1.useEffect)(function () {
        getSegments();
    }, [getSegments]);
    return {
        segments: segments,
        isLoading: isLoading
    };
};
exports.useSegmentationRequest = useSegmentationRequest;
