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