/*
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 { 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
 */
export let UltraCalcFunctionLookupBase = /*@__PURE__*/ (() => {
    class UltraCalcFunctionLookupBase extends BuiltInFunctionBase {
        static _am(a, b, c, d, e, f, g) {
            let h = a._getResolvedValue();
            if (ExcelUtils.ba(h)) {
                return toNullable(Number_$type, null);
            }
            if (b) {
                if (ExcelCalcValue._ak(h) == false) {
                    return toNullable(Number_$type, null);
                }
                let i = a._bt(h, a._a4);
                if (g == null) {
                    return toNullable(Number_$type, StringUtilities.d(i, c, a._a4, 1));
                }
                let 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));
            }
            let k;
            let l;
            if (((() => { let m = a._as(h, k, a._a4, l); k = m.p1; l = m.p3; return m.ret; })()) == false) {
                return toNullable(Number_$type, null);
            }
            return toNullable(Number_$type, Base.compareSimple(k, f));
        }
        static _an(a) {
            let b;
            return ((() => { let c = ExcelUtils.er(a, b); b = c.p1; return c.ret; })());
        }
        static _al(a, b, c) {
            let d = b.isString;
            let e = d ? b.toString() : null;
            let f = b.isBoolean;
            let g = f ? b._toBoolean1() : false;
            let h = 0;
            if (f == false && d == false) {
                let i = b._toDouble1(h);
                h = i.p0;
            }
            let j = null;
            if (d && c == 0) {
                j = UltraCalcFunctionLookupBase._an(e);
            }
            let k = -1;
            for (let l of fromEnum(a)) {
                let m = l.key;
                let n = l.value;
                n._ac = true;
                let 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;
                        }
                    }
                }
            }
            return k;
        }
        static _ak(a, b) {
            b = true;
            if (a != null) {
                if (a.isBoolean) {
                    b = a._toBoolean1();
                }
                else if (a.isDateTime) {
                    b = true;
                }
                else {
                    let c;
                    if (((() => { let d = a._toDouble1(c); c = d.p0; return d.ret; })())) {
                        b = (c != 0);
                    }
                    else {
                        return {
                            ret: false,
                            p1: b
                        };
                    }
                }
            }
            return {
                ret: true,
                p1: b
            };
        }
        get_minArgs() {
            return 3;
        }
        get minArgs() {
            return this.get_minArgs();
        }
        get_maxArgs() {
            return 4;
        }
        get maxArgs() {
            return this.get_maxArgs();
        }
        _v(a) {
            if (a == 1) {
                return false;
            }
            return true;
        }
    }
    UltraCalcFunctionLookupBase.$t = markType(UltraCalcFunctionLookupBase, 'UltraCalcFunctionLookupBase', BuiltInFunctionBase.$);
    return UltraCalcFunctionLookupBase;
})();
