"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AttributeRule = void 0;
var react_1 = __importDefault(require("react"));
var classnames_1 = __importDefault(require("classnames"));
var ramda_1 = require("ramda");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var ComplexRule_1 = require("../ComplexRule");
var SimpleRule_1 = require("../SimpleRule");
var AttributeTitle_1 = require("../../../../../AttributeTitle");
var SyncedValueHeight_1 = require("../../../../../SyncedValueHeight");
var AttributeRule_module_css_1 = __importDefault(require("./AttributeRule.module.css"));
var AttributeRule = function (_a) {
    var attributeType = _a.attributeType, values = _a.values, getRuleTypeData = _a.getRuleTypeData, parentUri = _a.parentUri;
    var ovValues = (0, ramda_1.filter)(mdm_sdk_1.isOv, values);
    var blockUri = parentUri ? "".concat(parentUri, "/").concat(attributeType.uri) : attributeType.uri;
    var renderValue = function (value) {
        var content = (0, mdm_sdk_1.isComplexAttribute)(attributeType) ? (react_1.default.createElement(ComplexRule_1.ComplexRule, { attributeType: attributeType, attributeValue: value, getRuleTypeData: getRuleTypeData })) : (react_1.default.createElement(SimpleRule_1.SimpleRule, { attributeValue: value, attributeType: attributeType, getRuleTypeData: getRuleTypeData }));
        return (react_1.default.createElement(SyncedValueHeight_1.ValueHeightConsumer, { key: value.uri, uri: value.uri }, content));
    };
    return ovValues.length === 1 && !(0, mdm_sdk_1.isComplexAttribute)(attributeType) ? (react_1.default.createElement(SyncedValueHeight_1.ValueHeightConsumer, { uri: ovValues[0].uri },
        react_1.default.createElement("div", { className: AttributeRule_module_css_1.default.oneLineRule },
            react_1.default.createElement(AttributeTitle_1.AttributeTitle, { label: attributeType.label, className: (0, classnames_1.default)(AttributeRule_module_css_1.default.label, AttributeRule_module_css_1.default.labelMargin) }),
            react_1.default.createElement(SimpleRule_1.SimpleRule, { attributeValue: ovValues[0], attributeType: attributeType, getRuleTypeData: getRuleTypeData })))) : (react_1.default.createElement(SyncedValueHeight_1.ValueHeightConsumer, { uri: blockUri },
        react_1.default.createElement(react_1.default.Fragment, null,
            react_1.default.createElement(AttributeTitle_1.AttributeTitle, { label: attributeType.label, className: AttributeRule_module_css_1.default.label }),
            react_1.default.createElement("div", { className: AttributeRule_module_css_1.default.valuesList }, values.map(renderValue)))));
};
exports.AttributeRule = AttributeRule;
