"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useChangesList = void 0;
var react_1 = require("react");
var ramda_1 = require("ramda");
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var merge_1 = require("../helpers/merge");
var MdmModuleContext_1 = require("../../../contexts/MdmModuleContext");
var useChangesList = function (_a) {
    var changes = _a.changes, entityInfo = _a.entityInfo, relationsInfo = _a.relationsInfo;
    var metadata = (0, MdmModuleContext_1.useMdmMetadata)();
    var _b = (0, react_1.useMemo)(function () { return (0, merge_1.mergeChanges)(metadata, changes, entityInfo, relationsInfo); }, [metadata, changes, entityInfo, relationsInfo]), mergedEntityChanges = _b[0], mergedRelationsChanges = _b[1];
    var changesList = (0, react_1.useMemo)(function () {
        var relationshipTitle = { label: ui_i18n_1.default.text('Relationships') };
        return mergedRelationsChanges.length > 0
            ? (0, ramda_1.flatten)([mergedEntityChanges, relationshipTitle, mergedRelationsChanges])
            : mergedEntityChanges;
    }, [mergedEntityChanges, mergedRelationsChanges]);
    return changesList;
};
exports.useChangesList = useChangesList;
