"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MatchRulesBlock = void 0;
var react_1 = __importDefault(require("react"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var SimpleMatchRulesBlock_1 = require("../SimpleMatchRulesBlock");
var TransitiveMatchBlock_1 = require("../TransitiveMatchBlock");
var SimpleMatchRulesBuilder_1 = require("../SimpleMatchRulesBuilder");
var NotMatchRule_1 = require("../NotMatchRule");
var types_1 = require("../types");
var MatchRulesBlock = function (_a) {
    var entitiesMap = _a.entitiesMap, entity = _a.entity, match = _a.match, metadata = _a.metadata, _b = _a.variant, variant = _b === void 0 ? types_1.MatchRuleVariant.all : _b;
    if (!match.matchRules && !match.negativeRules) {
        return null;
    }
    var isTransitive = (0, mdm_sdk_1.isTransitiveMatch)(match);
    var matchRules = (0, mdm_sdk_1.getMatchRules)(metadata, entity.type, (match.matchRules || []).concat(match.negativeRules || []));
    var rules = matchRules.filter(function (_a) {
        var uri = _a.uri;
        return uri !== mdm_sdk_1.NOT_MATCH;
    });
    var hasNotMatch = rules.length !== matchRules.length;
    var showSimple = !isTransitive && !hasNotMatch;
    var showNotMatch = hasNotMatch && variant !== types_1.MatchRuleVariant.excludeNotMatch;
    return (react_1.default.createElement(react_1.default.Fragment, null,
        isTransitive ? (react_1.default.createElement(TransitiveMatchBlock_1.TransitiveMatchBlock, { transitiveMatchRules: (0, mdm_sdk_1.getTransitiveMatchRules)(metadata, match, entitiesMap), matchRuleSummaries: match.matchRuleSummaries })) : null,
        showSimple ? (react_1.default.createElement(SimpleMatchRulesBuilder_1.SimpleMatchRulesBuilder, { variant: variant, matchRules: matchRules, matchRuleSummaries: match.matchRuleSummaries, Component: SimpleMatchRulesBlock_1.SimpleMatchRulesBlock })) : null,
        showNotMatch ? react_1.default.createElement(NotMatchRule_1.NotMatchRule, null) : null));
};
exports.MatchRulesBlock = MatchRulesBlock;
