/*
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 { markType } from "igniteui-angular-core";
import { Workbook } from "./Workbook";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { ExcelUtils } from "./ExcelUtils";
import { CellAddress } from "./CellAddress";
import { stringEmpty } from "igniteui-angular-core";
/**
 * @hidden
 */
export let UltraCalcFunctionAddress = /*@__PURE__*/ (() => {
    class UltraCalcFunctionAddress extends BuiltInFunctionBase {
        evaluate(a, b) {
            let c = null;
            if (b == 5) {
                c = a.pop();
            }
            let d = null;
            if (b >= 4) {
                d = a.pop();
            }
            let e = null;
            if (b >= 3) {
                e = a.pop();
            }
            let f = a.pop();
            let g = a.pop();
            if (g.isError) {
                return g;
            }
            if (f.isError) {
                return f;
            }
            if (e != null && e.isError) {
                return e;
            }
            if (d != null && d.isError) {
                return d;
            }
            if (c != null && c.isError) {
                return c;
            }
            let h = g._toInt321();
            let i = f._toInt321();
            let j = e == null || e.isNull ? 1 : e._toInt321();
            let k = d == null || d.isNull ? true : d._toBoolean1();
            let l = c == null || c.isNull ? null : c.toString();
            let m = this._ak(a);
            let n = Workbook.getMaxRowCount(m);
            let o = Workbook.getMaxColumnCount(m);
            if (h < 1 || n < h) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(1));
            }
            if (i < 1 || o < i) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(1));
            }
            let p;
            let q;
            switch (j) {
                case 1:
                    p = false;
                    q = false;
                    break;
                case 2:
                    p = false;
                    q = true;
                    break;
                case 3:
                    p = true;
                    q = false;
                    break;
                case 4:
                    p = true;
                    q = true;
                    break;
                default: return new ExcelCalcValue(new ExcelCalcErrorValue(1));
            }
            let r = k ? 1 : 0;
            let s = stringEmpty();
            if (l != null) {
                s += ExcelUtils.d7(null, l);
            }
            if (r == 0) {
                if (p) {
                    h++;
                }
                if (q) {
                    i++;
                }
            }
            s += CellAddress.u(h - 1, i - 1, m, p, q, void 0, void 0, void 0, r);
            return new ExcelCalcValue(s);
        }
        _ak(a) {
            let b = a._r;
            if (b != null) {
                return b.currentFormat;
            }
            return 2;
        }
        get_name() {
            return "address";
        }
        get name() {
            return this.get_name();
        }
        get_minArgs() {
            return 2;
        }
        get minArgs() {
            return this.get_minArgs();
        }
        get_maxArgs() {
            return 5;
        }
        get maxArgs() {
            return this.get_maxArgs();
        }
        doesParameterAllowIntermediateResultArray(a, b) {
            if (a == 3) {
                return false;
            }
            return true;
        }
    }
    UltraCalcFunctionAddress.$t = markType(UltraCalcFunctionAddress, 'UltraCalcFunctionAddress', BuiltInFunctionBase.$);
    return UltraCalcFunctionAddress;
})();
