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);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { memo } from 'react';
import { DataTypes } from '@reltio/mdm-sdk';
import { ReadOnlyAttribute } from '../ReadOnlyAttributesFactory';
import { ReadOnlyImageAttributesLine } from '../ReadOnlyImageAttributesLine';
import { LazyRenderer } from '../LazyRenderer';
var lazyRendererStyle = { height: '18px' };
var renderAttributesList = function (_a) {
    var values = _a.values, valueContainerClassName = _a.valueContainerClassName, AttributeValueWrapper = _a.AttributeValueWrapper, props = __rest(_a, ["values", "valueContainerClassName", "AttributeValueWrapper"]);
    var enabledLazyRendering = (values === null || values === void 0 ? void 0 : values.length) > 20;
    return (React.createElement(React.Fragment, null, (values || []).map(function (attributeValue) { return (React.createElement(LazyRenderer, { key: attributeValue.uri, className: valueContainerClassName, enabled: enabledLazyRendering, style: lazyRendererStyle },
        React.createElement("div", { className: valueContainerClassName }, AttributeValueWrapper ? (React.createElement(AttributeValueWrapper, { uri: attributeValue.uri },
            React.createElement(ReadOnlyAttribute, __assign({ attributeValue: attributeValue }, props)))) : (React.createElement(ReadOnlyAttribute, __assign({ attributeValue: attributeValue }, props)))))); })));
};
var ReadOnlyAttributeValuesBlock = function (_a) {
    var expanded = _a.expanded, LabelRenderer = _a.LabelRenderer, RightSlot = _a.RightSlot, props = __rest(_a, ["expanded", "LabelRenderer", "RightSlot"]);
    var attributeType = props.attributeType, values = props.values, valueContainerClassName = props.valueContainerClassName;
    switch (attributeType.type) {
        case DataTypes.TYPE_NESTED:
        case DataTypes.TYPE_REFERENCE: {
            return renderAttributesList(__assign({ expanded: expanded, LabelRenderer: LabelRenderer, RightSlot: RightSlot }, props));
        }
        case DataTypes.TYPE_IMAGE: {
            return (React.createElement("div", { className: valueContainerClassName },
                React.createElement(ReadOnlyImageAttributesLine, { attributeType: attributeType, attributeValues: values, imageSize: { imageHeight: 40, imageWidth: 40, imageMargin: 2 } })));
        }
        default: {
            return renderAttributesList(__assign({}, props));
        }
    }
};
export default memo(ReadOnlyAttributeValuesBlock);
