/*
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 { BuiltInFunctionBase } from "./BuiltInFunctionBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { fromEn, markType } from "igniteui-angular-core";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
/**
 * @hidden
 */
export let UltraCalcFunctionNPV = /*@__PURE__*/ (() => {
    class UltraCalcFunctionNPV extends BuiltInFunctionBase {
        evaluate(a, b) {
            let c;
            let d = 0;
            let e = new Array(b - 1);
            for (let f = 0; f < b - 1; f++) {
                e[f] = a.pop();
            }
            let g;
            if (!((() => { let h = a.pop()._toDouble1(g); g = h.p0; return h.ret; })())) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(4));
            }
            g += 1;
            let h = 1;
            for (let i = e.length; i > 0; i--) {
                let j = e[i - 1];
                if (j.isReference && j.toReference().isEnumerable) {
                    let k = j.toReference().references;
                    for (let l of fromEn(k)) {
                        let m = l.value;
                        if (m.isError) {
                            return new ExcelCalcValue(m.toErrorValue());
                        }
                        if (((() => { let n = m._toDouble1(c); c = n.p0; return n.ret; })())) {
                            d += c / Math.pow(g, h++);
                        }
                    }
                }
                else {
                    if (j.isError) {
                        return new ExcelCalcValue(j.toErrorValue());
                    }
                    if (((() => { let n = j._toDouble1(c); c = n.p0; return n.ret; })())) {
                        d += c / Math.pow(g, h++);
                    }
                }
            }
            return new ExcelCalcValue(d);
        }
        canParameterBeEnumerable(a) {
            return 1 <= a;
        }
        get_name() {
            return "npv";
        }
        get name() {
            return this.get_name();
        }
        get_minArgs() {
            return 2;
        }
        get minArgs() {
            return this.get_minArgs();
        }
        get_maxArgs() {
            return 0x7FFFFFFF;
        }
        get maxArgs() {
            return this.get_maxArgs();
        }
    }
    UltraCalcFunctionNPV.$t = markType(UltraCalcFunctionNPV, 'UltraCalcFunctionNPV', BuiltInFunctionBase.$);
    return UltraCalcFunctionNPV;
})();
