import i18n from 'ui-i18n';
import { allPass, always, cond, isNil, has, not, pipe, propSatisfies, T } from 'ramda';
var valueCaption = function (value) {
    return i18n.text('${value}', {
        value: value === 1 ? i18n.text('value') : i18n.text('values')
    });
};
var hasMinValue = has('minValue');
var hasMaxValue = has('maxValue');
var noMaxValue = pipe(hasMaxValue, not);
var minValueIsOne = propSatisfies(function (minValue) { return minValue === 1; }, 'minValue');
var exactCardinality = function (_a) {
    var minValue = _a.minValue, maxValue = _a.maxValue;
    return minValue && minValue === maxValue;
};
var generateMinCardinality = function (_a) {
    var minValue = _a.minValue;
    return i18n.text('This attribute can have minimum ${minValue} ${minValueCaption}', {
        minValue: i18n.number(minValue, '0'),
        minValueCaption: valueCaption(minValue)
    });
};
var generateMaxCardinality = function (_a) {
    var maxValue = _a.maxValue;
    return i18n.text('This attribute can have maximum ${maxValue} ${maxValueCaption}', {
        maxValue: i18n.number(maxValue, '0'),
        maxValueCaption: valueCaption(maxValue)
    });
};
var generateExactCardinality = function (_a) {
    var minValue = _a.minValue;
    return i18n.text('This attribute should have ${minValue} ${minValueCaption}', {
        minValue: i18n.number(minValue, '0'),
        minValueCaption: valueCaption(minValue)
    });
};
var generateMinMaxCardinality = function (_a) {
    var minValue = _a.minValue, maxValue = _a.maxValue;
    return i18n.text('${minCardinality} and maximum ${maxValue} ${maxValueCaption}', {
        minCardinality: generateMinCardinality({ minValue: minValue }),
        maxValue: i18n.number(maxValue, '0'),
        maxValueCaption: valueCaption(maxValue)
    });
};
export var getCardinalityMessage = cond([
    [isNil, always('')],
    [exactCardinality, generateExactCardinality],
    [allPass([minValueIsOne, hasMaxValue]), generateMaxCardinality],
    [allPass([minValueIsOne, noMaxValue]), always('')],
    [allPass([hasMinValue, hasMaxValue]), generateMinMaxCardinality],
    [hasMaxValue, generateMaxCardinality],
    [hasMinValue, generateMinCardinality],
    [T, always('')]
]);
