import React from 'react';
import classnames from 'classnames';
import { filter } from 'ramda';
import { isComplexAttribute, isOv } from '@reltio/mdm-sdk';
import { ComplexRule } from '../ComplexRule';
import { SimpleRule } from '../SimpleRule';
import { AttributeTitle } from '../../../../../AttributeTitle';
import { ValueHeightConsumer } from '../../../../../SyncedValueHeight';
import styles from './AttributeRule.module.css';
export var AttributeRule = function (_a) {
    var attributeType = _a.attributeType, values = _a.values, getRuleTypeData = _a.getRuleTypeData, parentUri = _a.parentUri;
    var ovValues = filter(isOv, values);
    var blockUri = parentUri ? "".concat(parentUri, "/").concat(attributeType.uri) : attributeType.uri;
    var renderValue = function (value) {
        var content = isComplexAttribute(attributeType) ? (React.createElement(ComplexRule, { attributeType: attributeType, attributeValue: value, getRuleTypeData: getRuleTypeData })) : (React.createElement(SimpleRule, { attributeValue: value, attributeType: attributeType, getRuleTypeData: getRuleTypeData }));
        return (React.createElement(ValueHeightConsumer, { key: value.uri, uri: value.uri }, content));
    };
    return ovValues.length === 1 && !isComplexAttribute(attributeType) ? (React.createElement(ValueHeightConsumer, { uri: ovValues[0].uri },
        React.createElement("div", { className: styles.oneLineRule },
            React.createElement(AttributeTitle, { label: attributeType.label, className: classnames(styles.label, styles.labelMargin) }),
            React.createElement(SimpleRule, { attributeValue: ovValues[0], attributeType: attributeType, getRuleTypeData: getRuleTypeData })))) : (React.createElement(ValueHeightConsumer, { uri: blockUri },
        React.createElement(React.Fragment, null,
            React.createElement(AttributeTitle, { label: attributeType.label, className: styles.label }),
            React.createElement("div", { className: styles.valuesList }, values.map(renderValue)))));
};
