/*
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 { __extends } from "tslib";
import { UltraCalcFunctionLookupBase } from "./UltraCalcFunctionLookupBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { RegionArrayProxyBase } from "./RegionArrayProxyBase";
import { typeCast, markType } from "igniteui-angular-core";
import { truncate } from "igniteui-angular-core";
/**
 * @hidden
 */
var UltraCalcFunctionVLookup = /** @class */ /*@__PURE__*/ (function (_super) {
    __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);
        if (typeCast(RegionArrayProxyBase.$, g) !== null) {
            var l = g._b(0, 0, k - 1, 0);
            var m = l;
            var n = m._s._c;
            a._p._addDynamicReference1(n, a._r._w, true);
        }
        var o = UltraCalcFunctionLookupBase._al(g._j(0, 0), f, j ? 1 : 0);
        if (o < 0 || k <= o) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(3));
        }
        var p = g.getLength(0);
        if (p <= i) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(0));
        }
        var q = g.item(i, o);
        q._ac = true;
        return new ExcelCalcValue(q._getResolvedValue());
    };
    UltraCalcFunctionVLookup.prototype.get_name = function () {
        return "vlookup";
    };
    Object.defineProperty(UltraCalcFunctionVLookup.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionVLookup.$t = markType(UltraCalcFunctionVLookup, 'UltraCalcFunctionVLookup', UltraCalcFunctionLookupBase.$);
    return UltraCalcFunctionVLookup;
}(UltraCalcFunctionLookupBase));
export { UltraCalcFunctionVLookup };
