/*
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 { markType } from "igniteui-angular-core";
/**
 * @hidden
 */
export 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));
            }
        }
        let o = UltraCalcFunctionLookupBase._al(f._i(i ? 1 : 0, 0), e, 1);
        if (o < 0 || j <= o) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(3));
        }
        let p;
        if (k != null) {
            if (n) {
                if (l <= o) {
                    return new ExcelCalcValue(new ExcelCalcErrorValue(3));
                }
                p = k.item(o, 0);
            }
            else {
                if (m <= o) {
                    return new ExcelCalcValue(new ExcelCalcErrorValue(3));
                }
                p = k.item(0, o);
            }
        }
        else {
            if (i) {
                p = f.item(o, h - 1);
            }
            else {
                p = f.item(g - 1, o);
            }
        }
        p._y = true;
        return new ExcelCalcValue(p._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.$);
//# sourceMappingURL=UltraCalcFunctionLookup.js.map