"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildEntityOptions = void 0;
var ramda_1 = require("ramda");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var buildEntityOptions = function (entityTypes, onCreate) { return function (entities) {
    var newOptions = entities.map(function (entity) { return (__assign(__assign({}, entity), { label: (0, mdm_sdk_1.getLabel)(entity.label), entityType: entityTypes.find(function (_a) {
            var uri = _a.uri;
            return uri === entity.type;
        }) })); });
    var addDummyOptionToEmptyOptionList = function (options) {
        return (0, ramda_1.isEmpty)(options)
            ? [
                {
                    label: '',
                    uri: '',
                    entityType: {}
                }
            ]
            : options;
    };
    var filteredEntityTypes = onCreate
        ? entityTypes
        : entityTypes.filter(function (type) {
            return newOptions.some(function (option) { return option.type === type.uri; });
        });
    return filteredEntityTypes.length > 1
        ? filteredEntityTypes.map(function (type) {
            return {
                label: type.label,
                entityType: type.uri,
                options: addDummyOptionToEmptyOptionList(newOptions.filter(function (option) { return option.type === type.uri; }))
            };
        })
        : addDummyOptionToEmptyOptionList(newOptions);
}; };
exports.buildEntityOptions = buildEntityOptions;
