/*
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 { UltraCalcFunctionLookupBase } from "./UltraCalcFunctionLookupBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { markType } from "igniteui-angular-core";
/**
 * @hidden
 */
var UltraCalcFunctionLookup = /** @class */ (function (_super) {
    tslib_1.__extends(UltraCalcFunctionLookup, _super);
    function UltraCalcFunctionLookup() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionLookup.prototype.evaluate = function (a, b) {
        var c = null;
        if (b == 3) {
            c = a.pop();
        }
        var d = a.pop();
        var e = a.pop();
        if (e.isError) {
            return e;
        }
        if (d.isError) {
            return d;
        }
        if (c != null && c.isError) {
            return c;
        }
        if (e.isNull) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(3));
        }
        var f = d._d(false);
        var g = f.getLength(0);
        var h = f.getLength(1);
        var i = (h < g);
        var j = i ? g : h;
        var k = null;
        var l = 0;
        var m = 0;
        var n = false;
        if (c != null) {
            k = c.toArrayProxy();
            l = k.getLength(0);
            m = k.getLength(1);
            if (l == 1) {
                n = false;
            }
            else if (m == 1) {
                n = true;
            }
            else {
                return new ExcelCalcValue(new ExcelCalcErrorValue(3));
            }
        }
        var o = UltraCalcFunctionLookupBase._al(f._i(i ? 1 : 0, 0), e, 1);
        if (o < 0 || j <= o) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(3));
        }
        var p;
        if (k != null) {
            if (n) {
                if (l <= o) {
                    return new ExcelCalcValue(new ExcelCalcErrorValue(3));
                }
                p = k.item(o, 0);
            }
            else {
                if (m <= o) {
                    return new ExcelCalcValue(new ExcelCalcErrorValue(3));
                }
                p = k.item(0, o);
            }
        }
        else {
            if (i) {
                p = f.item(o, h - 1);
            }
            else {
                p = f.item(g - 1, o);
            }
        }
        p._y = true;
        return new ExcelCalcValue(p._getResolvedValue());
    };
    UltraCalcFunctionLookup.prototype.get_minArgs = function () {
        return 2;
    };
    UltraCalcFunctionLookup.prototype.get_maxArgs = function () {
        return 3;
    };
    UltraCalcFunctionLookup.prototype.get_name = function () {
        return "lookup";
    };
    Object.defineProperty(UltraCalcFunctionLookup.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionLookup.prototype.doesParameterAllowIntermediateResultArray = function (a, b) {
        if (a == 1) {
            return true;
        }
        return (b == false);
    };
    UltraCalcFunctionLookup.$t = markType(UltraCalcFunctionLookup, 'UltraCalcFunctionLookup', UltraCalcFunctionLookupBase.$);
    return UltraCalcFunctionLookup;
}(UltraCalcFunctionLookupBase));
export { UltraCalcFunctionLookup };
//# sourceMappingURL=UltraCalcFunctionLookup.js.map