/*
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 { fromEn, markType } from "igniteui-angular-core";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
/**
 * @hidden
 */
var UltraCalcFunctionNPV = /** @class */ (function (_super) {
    tslib_1.__extends(UltraCalcFunctionNPV, _super);
    function UltraCalcFunctionNPV() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionNPV.prototype.evaluate = function (a, b) {
        var c;
        var d = 0;
        var e = new Array(b - 1);
        for (var f = 0; f < b - 1; f++) {
            e[f] = a.pop();
        }
        var g;
        if (!((function () { var h = a.pop()._toDouble1(g); g = h.p0; return h.ret; })())) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(4));
        }
        g += 1;
        var h = 1;
        var _loop_1 = function (i) {
            var e_1, _a;
            var j = e[i - 1];
            if (j.isReference && j.toReference().isEnumerable) {
                var k = j.toReference().references;
                var _loop_2 = function (l) {
                    var m = l.value;
                    if (m.isError) {
                        return { value: new ExcelCalcValue(m.toErrorValue()) };
                    }
                    if (((function () { var n = m._toDouble1(c); c = n.p0; return n.ret; })())) {
                        d += c / Math.pow(g, h++);
                    }
                };
                try {
                    for (var _b = (e_1 = void 0, tslib_1.__values(fromEn(k))), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var l = _c.value;
                        var state_2 = _loop_2(l);
                        if (typeof state_2 === "object")
                            return state_2;
                    }
                }
                catch (e_1_1) { e_1 = { error: e_1_1 }; }
                finally {
                    try {
                        if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                    }
                    finally { if (e_1) throw e_1.error; }
                }
            }
            else {
                if (j.isError) {
                    return { value: new ExcelCalcValue(j.toErrorValue()) };
                }
                if (((function () { var n = j._toDouble1(c); c = n.p0; return n.ret; })())) {
                    d += c / Math.pow(g, h++);
                }
            }
        };
        for (var i = e.length; i > 0; i--) {
            var state_1 = _loop_1(i);
            if (typeof state_1 === "object")
                return state_1.value;
        }
        return new ExcelCalcValue(d);
    };
    UltraCalcFunctionNPV.prototype.canParameterBeEnumerable = function (a) {
        return 1 <= a;
    };
    UltraCalcFunctionNPV.prototype.get_name = function () {
        return "npv";
    };
    Object.defineProperty(UltraCalcFunctionNPV.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionNPV.prototype.get_minArgs = function () {
        return 2;
    };
    Object.defineProperty(UltraCalcFunctionNPV.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionNPV.prototype.get_maxArgs = function () {
        return 0x7FFFFFFF;
    };
    Object.defineProperty(UltraCalcFunctionNPV.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionNPV.$t = markType(UltraCalcFunctionNPV, 'UltraCalcFunctionNPV', BuiltInFunctionBase.$);
    return UltraCalcFunctionNPV;
}(BuiltInFunctionBase));
export { UltraCalcFunctionNPV };
//# sourceMappingURL=UltraCalcFunctionNPV.js.map