/*
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 { __extends } from "tslib";
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
 */
var UltraCalcFunctionAddress = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(UltraCalcFunctionAddress, _super);
    function UltraCalcFunctionAddress() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionAddress.prototype.evaluate = function (a, b) {
        var c = null;
        if (b == 5) {
            c = a.pop();
        }
        var d = null;
        if (b >= 4) {
            d = a.pop();
        }
        var e = null;
        if (b >= 3) {
            e = a.pop();
        }
        var f = a.pop();
        var 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;
        }
        var h = g._toInt321();
        var i = f._toInt321();
        var j = e == null || e.isNull ? 1 : e._toInt321();
        var k = d == null || d.isNull ? true : d._toBoolean1();
        var l = c == null || c.isNull ? null : c.toString();
        var m = this._ak(a);
        var n = Workbook.getMaxRowCount(m);
        var 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));
        }
        var p;
        var 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));
        }
        var r = k ? 1 : 0;
        var 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);
    };
    UltraCalcFunctionAddress.prototype._ak = function (a) {
        var b = a._r;
        if (b != null) {
            return b.currentFormat;
        }
        return 2;
    };
    UltraCalcFunctionAddress.prototype.get_name = function () {
        return "address";
    };
    Object.defineProperty(UltraCalcFunctionAddress.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionAddress.prototype.get_minArgs = function () {
        return 2;
    };
    Object.defineProperty(UltraCalcFunctionAddress.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionAddress.prototype.get_maxArgs = function () {
        return 5;
    };
    Object.defineProperty(UltraCalcFunctionAddress.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionAddress.prototype.doesParameterAllowIntermediateResultArray = function (a, b) {
        if (a == 3) {
            return false;
        }
        return true;
    };
    UltraCalcFunctionAddress.$t = markType(UltraCalcFunctionAddress, 'UltraCalcFunctionAddress', BuiltInFunctionBase.$);
    return UltraCalcFunctionAddress;
}(BuiltInFunctionBase));
export { UltraCalcFunctionAddress };
