"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFilterLabel = void 0;
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var ramda_1 = require("ramda");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var activities_1 = require("../utils/activities");
var getFilterLabel = function (filters) {
    var getLabel = (0, ramda_1.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 = (0, ramda_1.pipe)((0, ramda_1.map)(activities_1.getActivityLabel), getLabel(ui_i18n_1.default.text('activity'), ui_i18n_1.default.text('activities')))(filters.activities);
    var userLabel = getLabel(ui_i18n_1.default.text('user'), ui_i18n_1.default.text('users'), filters.users);
    var entityTypesLabel = (0, ramda_1.pipe)((0, ramda_1.defaultTo)([]), (0, ramda_1.pluck)('label'), (0, ramda_1.sortBy)(ramda_1.identity), getLabel(ui_i18n_1.default.text('type'), ui_i18n_1.default.text('types')))(filters.entityTypes);
    var attributesLabel = (0, ramda_1.pipe)((0, ramda_1.defaultTo)([]), (0, ramda_1.pluck)('label'), (0, ramda_1.sortBy)(ramda_1.identity), getLabel(ui_i18n_1.default.text('attribute'), ui_i18n_1.default.text('attributes')))(filters.attributes);
    var sourcesLabel = (0, ramda_1.pipe)((0, ramda_1.defaultTo)([]), (0, ramda_1.pluck)('label'), getLabel(ui_i18n_1.default.text('source'), ui_i18n_1.default.text('sources')))(filters.sources);
    var getDateLabel = function (date) {
        var formatDateValue = function (value) {
            return "".concat((0, mdm_sdk_1.formatDataTypeValue)({ dataTypeDefinition: { type: mdm_sdk_1.DataTypes.TYPE_ACTIVENESS_DATE } }, value));
        };
        switch (date.type) {
            case mdm_sdk_1.DateRangeTypes.WITHIN:
                return ui_i18n_1.default.text('Within ${amount} ${unit}', {
                    amount: date.period[0],
                    unit: (0, mdm_sdk_1.getIntervalUnitLabel)(date.period[1])
                });
            case mdm_sdk_1.DateRangeTypes.AGO:
                return ui_i18n_1.default.text('More than ${amount} ${unit} ago', {
                    amount: date.period[0],
                    unit: (0, mdm_sdk_1.getIntervalUnitLabel)(date.period[1])
                });
            case mdm_sdk_1.DateRangeTypes.BETWEEN:
                return ui_i18n_1.default.text('${startDate} to ${endDate}', {
                    startDate: formatDateValue(date.period[0]),
                    endDate: formatDateValue(date.period[1])
                });
            default:
                return null;
        }
    };
    return (0, ramda_1.pipe)((0, ramda_1.reject)(ramda_1.isNil), (0, ramda_1.join)(' | '))([activityLabel, entityTypesLabel, attributesLabel, sourcesLabel, getDateLabel(filters.dateRange), userLabel]);
};
exports.getFilterLabel = getFilterLabel;
