/*
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 { UltraCalcFunctionLookupBase } from "./UltraCalcFunctionLookupBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { RegionArrayProxyBase } from "./RegionArrayProxyBase";
import { typeCast, markType } from "igniteui-angular-core";
/**
 * @hidden
 */
export let UltraCalcFunctionLookup = /*@__PURE__*/ (() => {
    class UltraCalcFunctionLookup extends UltraCalcFunctionLookupBase {
        evaluate(a, b) {
            let c = null;
            if (b == 3) {
                c = a.pop();
            }
            let d = a.pop();
            let 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));
            }
            let f = d._d(false);
            let g = f.getLength(0);
            let h = f.getLength(1);
            let i = (h < g);
            let j = i ? g : h;
            let k = null;
            let l = 0;
            let m = 0;
            let 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));
                }
            }
            if (typeCast(RegionArrayProxyBase.$, f) !== null) {
                let o = i ? 0 : f.getLength(1) - 1;
                let p = i ? f.getLength(0) - 1 : 0;
                let q = f._b(0, 0, o, p);
                let r = q;
                let s = r._s._c;
                a._p._addDynamicReference1(s, a._r._w, true);
            }
            let t = UltraCalcFunctionLookupBase._al(f._j(i ? 1 : 0, 0), e, 1);
            if (t < 0 || j <= t) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(3));
            }
            let u;
            if (k != null) {
                if (n) {
                    if (l <= t) {
                        return new ExcelCalcValue(new ExcelCalcErrorValue(3));
                    }
                    u = k.item(t, 0);
                }
                else {
                    if (m <= t) {
                        return new ExcelCalcValue(new ExcelCalcErrorValue(3));
                    }
                    u = k.item(0, t);
                }
            }
            else {
                if (i) {
                    u = f.item(t, h - 1);
                }
                else {
                    u = f.item(g - 1, t);
                }
            }
            u._ac = true;
            return new ExcelCalcValue(u._getResolvedValue());
        }
        get_minArgs() {
            return 2;
        }
        get_maxArgs() {
            return 3;
        }
        get_name() {
            return "lookup";
        }
        get name() {
            return this.get_name();
        }
        doesParameterAllowIntermediateResultArray(a, b) {
            if (a == 1) {
                return true;
            }
            return (b == false);
        }
    }
    UltraCalcFunctionLookup.$t = markType(UltraCalcFunctionLookup, 'UltraCalcFunctionLookup', UltraCalcFunctionLookupBase.$);
    return UltraCalcFunctionLookup;
})();
