import { checkCanCreateAttribute, findAttributeValuesByTypeUri, isImage, isNested, isReadableAttribute, isReference, Mode } from '@reltio/mdm-sdk';
import { both, either, filter, ifElse, isEmpty, isNil, pipe, propEq, propOr, reject } from 'ramda';
export var getAddableAttributeTypes = function (parentType, _a) {
    var _b = _a === void 0 ? {} : _a, _c = _b.personalizationEnabled, personalizationEnabled = _c === void 0 ? false : _c, selectedAttributeTypes = _b.selectedAttributeTypes, entity = _b.entity, metadata = _b.metadata;
    var isNotSelected = function (attrType) { return !(selectedAttributeTypes === null || selectedAttributeTypes === void 0 ? void 0 : selectedAttributeTypes.find(propEq('uri', attrType.uri))); };
    var canCreate = function (attributeType) { return checkCanCreateAttribute({ attributeType: attributeType, mode: Mode.Editing }); };
    var isVisibleInPicker = either(isNested, isNotSelected);
    var hasAttributeOnEntity = function (attributeType) {
        if (!entity || !metadata) {
            return false;
        }
        var values = findAttributeValuesByTypeUri(metadata, entity, attributeType.uri);
        return !isNil(values) && !isEmpty(values);
    };
    return pipe(propOr([], 'attributes'), ifElse(function () { return personalizationEnabled; }, pipe(filter(isReadableAttribute), filter(either(canCreate, hasAttributeOnEntity)), filter(isVisibleInPicker)), pipe(reject(either(isReference, isImage)), filter(isVisibleInPicker), filter(both(isReadableAttribute, canCreate)))))(parentType);
};
