/*
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 { BuiltInFunctionBase } from "./BuiltInFunctionBase";
import { Base, toNullable, Number_$type, fromEnum, markType } from "igniteui-angular-core";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { ExcelUtils } from "./ExcelUtils";
import { StringUtilities } from "./StringUtilities";
import { boolCompare } from "igniteui-angular-core";
/**
 * @hidden
 */
var UltraCalcFunctionLookupBase = /** @class */ (function (_super) {
    tslib_1.__extends(UltraCalcFunctionLookupBase, _super);
    function UltraCalcFunctionLookupBase() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionLookupBase._am = function (a, b, c, d, e, f, g) {
        var h = a._getResolvedValue();
        if (ExcelUtils.a8(h)) {
            return toNullable(Number_$type, null);
        }
        if (b) {
            if (ExcelCalcValue._ag(h) == false) {
                return toNullable(Number_$type, null);
            }
            var i = a._bp(h, a._a0);
            if (g == null) {
                return toNullable(Number_$type, StringUtilities.d(i, c, a._a0, 1));
            }
            var j = g.i(i);
            if (j.i && j.d == i.length) {
                return toNullable(Number_$type, 0);
            }
            return toNullable(Number_$type, -1);
        }
        if (d) {
            if (a.isBoolean == false) {
                return toNullable(Number_$type, null);
            }
            return toNullable(Number_$type, boolCompare(a._toBoolean1(), e));
        }
        var k;
        var l;
        if (((function () { var m = a._ao(h, k, a._a0, l); k = m.p1; l = m.p3; return m.ret; })()) == false) {
            return toNullable(Number_$type, null);
        }
        return toNullable(Number_$type, Base.compareSimple(k, f));
    };
    UltraCalcFunctionLookupBase._an = function (a) {
        var b;
        return ((function () { var c = ExcelUtils.ep(a, b); b = c.p1; return c.ret; })());
    };
    UltraCalcFunctionLookupBase._al = function (a, b, c) {
        var e_1, _a;
        var d = b.isString;
        var e = d ? b.toString() : null;
        var f = b.isBoolean;
        var g = f ? b._toBoolean1() : false;
        var h = 0;
        if (f == false && d == false) {
            var i = b._toDouble1(h);
            h = i.p0;
        }
        var j = null;
        if (d && c == 0) {
            j = UltraCalcFunctionLookupBase._an(e);
        }
        var k = -1;
        try {
            for (var _b = tslib_1.__values(fromEnum(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var l = _c.value;
                var m = l.key;
                var n = l.value;
                n._y = true;
                var o = UltraCalcFunctionLookupBase._am(n, d, e, f, g, h, j);
                if (o.hasValue == false) {
                    continue;
                }
                if (o.value == 0) {
                    return m;
                }
                if (c != 0) {
                    if (c < 0) {
                        if (o.value > 0) {
                            k = m;
                        }
                    }
                    else {
                        if (o.value < 0) {
                            k = m;
                        }
                    }
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_1) throw e_1.error; }
        }
        return k;
    };
    UltraCalcFunctionLookupBase._ak = function (a, b) {
        b = true;
        if (a != null) {
            if (a.isBoolean) {
                b = a._toBoolean1();
            }
            else if (a.isDateTime) {
                b = true;
            }
            else {
                var c_1;
                if (((function () { var d = a._toDouble1(c_1); c_1 = d.p0; return d.ret; })())) {
                    b = (c_1 != 0);
                }
                else {
                    return {
                        ret: false,
                        p1: b
                    };
                }
            }
        }
        return {
            ret: true,
            p1: b
        };
    };
    UltraCalcFunctionLookupBase.prototype.get_minArgs = function () {
        return 3;
    };
    Object.defineProperty(UltraCalcFunctionLookupBase.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionLookupBase.prototype.get_maxArgs = function () {
        return 4;
    };
    Object.defineProperty(UltraCalcFunctionLookupBase.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionLookupBase.prototype._v = function (a) {
        if (a == 1) {
            return false;
        }
        return true;
    };
    UltraCalcFunctionLookupBase.$t = markType(UltraCalcFunctionLookupBase, 'UltraCalcFunctionLookupBase', BuiltInFunctionBase.$);
    return UltraCalcFunctionLookupBase;
}(BuiltInFunctionBase));
export { UltraCalcFunctionLookupBase };
//# sourceMappingURL=UltraCalcFunctionLookupBase.js.map