import { either, identity, path } from 'ramda';
import i18n from 'ui-i18n';
import { AttributeValuePathItemType, ErrorSource, ErrorType, findAttributeTypeByUri } from '@reltio/mdm-sdk';
export var getDisplayedErrorMessage = function (metadata, _a) {
    var type = _a.type, source = _a.source, message = _a.message, _b = _a.attributeTypeUri, attributeTypeUri = _b === void 0 ? '' : _b, attributeType = _a.attributeType;
    if (type === ErrorType.missed && source === ErrorSource.local) {
        var attrType = attributeType || findAttributeTypeByUri(metadata, attributeTypeUri);
        return attrType ? i18n.text('${attribute} is required', { attribute: attrType.label }) : message;
    }
    return message;
};
export var getDisplayedErrorPath = function (_a) {
    var errorPath = _a.path, uri = _a.uri;
    return errorPath === null || errorPath === void 0 ? void 0 : errorPath.slice(0, uri ? errorPath.length - 1 : errorPath.length).filter(function (_a) {
        var type = _a.type;
        return [AttributeValuePathItemType.attributeValue, AttributeValuePathItemType.relationConnection].includes(type);
    }).map(function (_a) {
        var label = _a.label;
        return label;
    }).filter(identity).join(' / ');
};
export var getDisplayedAttributeTypesPath = function (_a) {
    var errorPath = _a.path;
    return errorPath === null || errorPath === void 0 ? void 0 : errorPath.filter(function (_a) {
        var type = _a.type;
        return type === AttributeValuePathItemType.attributeValue;
    }).map(either(path(['valueType', 'label']), path(['valueType', 'name']))).filter(identity).join(' > ');
};
