/*
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 { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { MatrixUtilities } from "./MatrixUtilities";
import { markType } from "igniteui-angular-core";
import { arrayGetLength } from "igniteui-angular-core";
/**
 * @hidden
 */
export class UltraCalcFunctionSumproduct extends BuiltInFunctionBase {
    evaluate(a, b) {
        let c = new Array(b);
        let d = 0;
        let e = 0;
        let f = 0;
        try {
            for (; f < b; f++) {
                let g = a.pop();
                if (g.isError) {
                    return g;
                }
                let h;
                let i = ((() => { let j = MatrixUtilities.b(g.toArrayProxy(), 1, h); h = j.p2; return j.ret; })());
                if (h != null) {
                    return new ExcelCalcValue(h);
                }
                if (f == 0) {
                    d = arrayGetLength(i, 0);
                    e = arrayGetLength(i, 1);
                }
                else {
                    if (d != arrayGetLength(i, 0) || e != arrayGetLength(i, 1)) {
                        return new ExcelCalcValue(new ExcelCalcErrorValue(1));
                    }
                }
                c[f] = i;
            }
        }
        finally {
            for (f++; f < b; f++) {
                a.pop();
            }
        }
        let j = 0;
        for (let k = 0; k < d; k++) {
            for (let l = 0; l < e; l++) {
                let m = 1;
                for (let n = 0; n < b; n++) {
                    m *= c[n][k][l];
                }
                j += m;
            }
        }
        return new ExcelCalcValue(j);
    }
    get_name() {
        return "sumproduct";
    }
    get name() {
        return this.get_name();
    }
    get_minArgs() {
        return 1;
    }
    get minArgs() {
        return this.get_minArgs();
    }
    get_maxArgs() {
        return 0x7FFFFFFF;
    }
    get maxArgs() {
        return this.get_maxArgs();
    }
    doesParameterAllowIntermediateResultArray(a, b) {
        return true;
    }
}
UltraCalcFunctionSumproduct.$t = markType(UltraCalcFunctionSumproduct, 'UltraCalcFunctionSumproduct', BuiltInFunctionBase.$);
//# sourceMappingURL=UltraCalcFunctionSumproduct.js.map