/*
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 { ExcelCalcValue } from "./ExcelCalcValue";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { markType } from "igniteui-angular-core";
/**
 * @hidden
 */
export let UltraCalcFunctionIndex = /*@__PURE__*/ (() => {
    class UltraCalcFunctionIndex extends BuiltInFunctionBase {
        evaluate(a, b) {
            let c = null;
            if (b == 4) {
                c = a.pop();
            }
            let d = null;
            if (b >= 3) {
                d = a.pop();
            }
            let e = a.pop();
            let f = a.pop();
            if (f.isReference == false && f.isError) {
                return f;
            }
            if (e.isError) {
                return e;
            }
            if (d != null && d.isError) {
                return d;
            }
            if (c != null && c.isError) {
                return c;
            }
            if (f.isReference == false) {
                if (f.isString || f.isBoolean) {
                    return new ExcelCalcValue(new ExcelCalcErrorValue(1));
                }
            }
            let g = e._toInt321() - 1;
            let h = (d == null ? 1 : d._toInt321()) - 1;
            let i = (c == null ? 1 : c._toInt321()) - 1;
            let j = f._b(false);
            if (j.length <= i) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(0));
            }
            let k = j[i];
            let l = k.getLength(0);
            let m = k.getLength(1);
            if (d == null && l > 1) {
                if (m == 1) {
                    h = g;
                    g = 0;
                }
                else {
                    return new ExcelCalcValue(new ExcelCalcErrorValue(0));
                }
            }
            if (l <= h || m <= g) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(0));
            }
            if (h < -1 || g < -1) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(1));
            }
            if (g == -1 || h == -1) {
                if (g == -1) {
                    if (h == -1) {
                        return new ExcelCalcValue(k);
                    }
                    else {
                        return new ExcelCalcValue(k._b(0, h, m - 1, h));
                    }
                }
                else {
                    return new ExcelCalcValue(k._b(g, 0, g, l - 1));
                }
            }
            return k.item(h, g);
        }
        get_name() {
            return "index";
        }
        get name() {
            return this.get_name();
        }
        get_minArgs() {
            return 2;
        }
        get minArgs() {
            return this.get_minArgs();
        }
        get_maxArgs() {
            return 4;
        }
        get maxArgs() {
            return this.get_maxArgs();
        }
        _v(a) {
            if (a == 0) {
                return false;
            }
            return true;
        }
    }
    UltraCalcFunctionIndex.$t = markType(UltraCalcFunctionIndex, 'UltraCalcFunctionIndex', BuiltInFunctionBase.$);
    return UltraCalcFunctionIndex;
})();
