import i18n from 'ui-i18n';
import { curry, join, identity, isNil, map, pipe, reject, sortBy, defaultTo, pluck } from 'ramda';
import { DataTypes, formatDataTypeValue, DateRangeTypes, getIntervalUnitLabel } from '@reltio/mdm-sdk';
import { getActivityLabel } from '../utils/activities';
export var getFilterLabel = function (filters) {
    var getLabel = curry(function (unit, pluralUnit, values) {
        return values.length <= 1
            ? values[0]
            : "".concat(values[0], " + ").concat(values.length - 1, " ").concat(values.length === 2 ? unit : pluralUnit);
    });
    var activityLabel = pipe(map(getActivityLabel), getLabel(i18n.text('activity'), i18n.text('activities')))(filters.activities);
    var userLabel = getLabel(i18n.text('user'), i18n.text('users'), filters.users);
    var entityTypesLabel = pipe(defaultTo([]), pluck('label'), sortBy(identity), getLabel(i18n.text('type'), i18n.text('types')))(filters.entityTypes);
    var attributesLabel = pipe(defaultTo([]), pluck('label'), sortBy(identity), getLabel(i18n.text('attribute'), i18n.text('attributes')))(filters.attributes);
    var sourcesLabel = pipe(defaultTo([]), pluck('label'), getLabel(i18n.text('source'), i18n.text('sources')))(filters.sources);
    var getDateLabel = function (date) {
        var formatDateValue = function (value) {
            return "".concat(formatDataTypeValue({ dataTypeDefinition: { type: DataTypes.TYPE_ACTIVENESS_DATE } }, value));
        };
        switch (date.type) {
            case DateRangeTypes.WITHIN:
                return i18n.text('Within ${amount} ${unit}', {
                    amount: date.period[0],
                    unit: getIntervalUnitLabel(date.period[1])
                });
            case DateRangeTypes.AGO:
                return i18n.text('More than ${amount} ${unit} ago', {
                    amount: date.period[0],
                    unit: getIntervalUnitLabel(date.period[1])
                });
            case DateRangeTypes.BETWEEN:
                return i18n.text('${startDate} to ${endDate}', {
                    startDate: formatDateValue(date.period[0]),
                    endDate: formatDateValue(date.period[1])
                });
            default:
                return null;
        }
    };
    return pipe(reject(isNil), join(' | '))([activityLabel, entityTypesLabel, attributesLabel, sourcesLabel, getDateLabel(filters.dateRange), userLabel]);
};
