"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var lodash_1 = require("lodash");
var filterGroup_service_1 = require("../filterGroup.service");
var RangeFilterGroup = (function (_super) {
    __extends(RangeFilterGroup, _super);
    function RangeFilterGroup(settings, transformService) {
        var _this = _super.call(this, settings) || this;
        _this.transformService = transformService;
        _this.getValue = settings.getValue;
        settings.options = lodash_1.map(settings.options, _this.buildRangeOption.bind(_this));
        _this.initOptions();
        return _this;
    }
    RangeFilterGroup.prototype.serialize = function () {
        var _this = this;
        return this.value$.asObservable().map(function (activeOption) {
            if (_this.isNullOption(activeOption)) {
                return null;
            }
            return {
                highInclusive: activeOption.highInclusive,
                highExclusive: activeOption.highExclusive,
                lowInclusive: activeOption.lowInclusive,
                lowExclusive: activeOption.lowExclusive,
            };
        });
    };
    RangeFilterGroup.prototype.buildRangeOption = function (option) {
        var _this = this;
        var modeOption = option;
        modeOption.predicate = function (item) {
            var value = _this.transformService.getValue(item, _this.getValue);
            var result = true;
            if (lodash_1.isUndefined(option.highExclusive) === false) {
                result = value < option.highExclusive;
            }
            else if (lodash_1.isUndefined(option.highInclusive) === false) {
                result = value <= option.highInclusive;
            }
            if (lodash_1.isUndefined(option.lowExclusive) === false) {
                result = result && value > option.lowExclusive;
            }
            else if (lodash_1.isUndefined(option.lowInclusive) === false) {
                result = result && value >= option.lowInclusive;
            }
            return result;
        };
        return modeOption;
    };
    RangeFilterGroup.prototype.isNullOption = function (option) {
        return option.highInclusive == null
            && option.highExclusive == null
            && option.lowInclusive == null
            && option.lowExclusive == null;
    };
    return RangeFilterGroup;
}(filterGroup_service_1.FilterGroup));
exports.RangeFilterGroup = RangeFilterGroup;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmFuZ2VGaWx0ZXJHcm91cC5zZXJ2aWNlLmpz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