/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import * as tslib_1 from "tslib";
import { BuiltInFunctionBase } from "./BuiltInFunctionBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { markType, getEnumerator } from "igniteui-angular-core";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
/**
 * @hidden
 */
var UltraCalcFunctionProbFunction = /** @class */ (function (_super) {
    tslib_1.__extends(UltraCalcFunctionProbFunction, _super);
    function UltraCalcFunctionProbFunction() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionProbFunction.prototype.evaluate = function (a, b) {
        var c = 0;
        if (b == 4) {
            c = a.pop()._toDecimal2();
        }
        var d = a.pop()._toDecimal2();
        if (b < 4) {
            c = d;
        }
        var e = a.pop().toArrayProxy();
        var f = a.pop().toArrayProxy();
        var g = e.getLength(0) * e.getLength(1);
        var h = f.getLength(0) * f.getLength(1);
        if (g != h) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(3));
        }
        var i = 0;
        var j = 0;
        var k = getEnumerator(e);
        var l = getEnumerator(f);
        while (k.moveNext()) {
            l.moveNext();
            var m = k.current;
            if (m.isError) {
                return new ExcelCalcValue(m.toErrorValue());
            }
            var n = l.current;
            if (n.isError) {
                return new ExcelCalcValue(n.toErrorValue());
            }
            var o = m._toDecimal2();
            if (o < 0 || o > 1) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(4));
            }
            if (o > 0) {
                if (n.isString) {
                    return new ExcelCalcValue(new ExcelCalcErrorValue(4));
                }
                if (n.isBoolean || m.isBoolean) {
                    return new ExcelCalcValue(new ExcelCalcErrorValue(2));
                }
                i += o;
                var p = n._toDecimal2();
                if (d <= p && p <= c) {
                    j += o;
                }
            }
        }
        if (i != 1) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(4));
        }
        return new ExcelCalcValue(j);
    };
    UltraCalcFunctionProbFunction.prototype.get_maxArgs = function () {
        return 4;
    };
    Object.defineProperty(UltraCalcFunctionProbFunction.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionProbFunction.prototype.get_minArgs = function () {
        return 3;
    };
    Object.defineProperty(UltraCalcFunctionProbFunction.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionProbFunction.prototype.get_name = function () {
        return "prob";
    };
    Object.defineProperty(UltraCalcFunctionProbFunction.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionProbFunction.$t = markType(UltraCalcFunctionProbFunction, 'UltraCalcFunctionProbFunction', BuiltInFunctionBase.$);
    return UltraCalcFunctionProbFunction;
}(BuiltInFunctionBase));
export { UltraCalcFunctionProbFunction };
//# sourceMappingURL=UltraCalcFunctionProbFunction.js.map