/*
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 { List$1 } from "igniteui-angular-core";
import { markType } from "igniteui-angular-core";
import { StringUtilities } from "./StringUtilities";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
/**
 * @hidden
 */
var UltraCalcFunctionSwitch = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(UltraCalcFunctionSwitch, _super);
    function UltraCalcFunctionSwitch() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionSwitch.prototype.evaluate = function (a, b) {
        var c = new List$1(ExcelCalcValue.$, 0);
        var d = null;
        if (b % 2 == 0) {
            d = a.pop();
            b--;
        }
        while (b > 1) {
            c.add(a.pop());
            b--;
        }
        var e = a.pop();
        if (e.isError) {
            return new ExcelCalcValue(e.toErrorValue());
        }
        var f, g, h, i;
        f = g = h = i = false;
        var j;
        if (e.isNull) {
            f = true;
            j = null;
        }
        else if (e.isString) {
            j = e.toString();
            h = true;
        }
        else if (e.isBoolean) {
            j = e._toBoolean1();
            g = true;
        }
        else {
            var k = e._toDouble3();
            j = k;
            if (k == 0) {
                f = true;
            }
            else {
                i = true;
            }
        }
        var _loop_1 = function (l) {
            var m = c._inner[l];
            var n = c._inner[l - 1];
            if (m.isError) {
                return { value: new ExcelCalcValue(m.toErrorValue()) };
            }
            var o = false;
            if (f || i) {
                if (!m.isString && !m.isBoolean) {
                    if (m.isNull) {
                        o = f;
                    }
                    else {
                        var p_1;
                        if (((function () { var q = m._toDouble1(p_1); p_1 = q.p0; return q.ret; })())) {
                            if (f) {
                                o = p_1 == 0;
                            }
                            else {
                                o = p_1 == j;
                            }
                        }
                    }
                }
            }
            else if (h) {
                o = m.isString && StringUtilities.d(j, m.toString(), a._w, 1) == 0;
            }
            else {
                o = m.isBoolean && m._toBoolean1() == j;
            }
            if (o) {
                return { value: n };
            }
        };
        for (var l = c.count - 1; l > 0; l -= 2) {
            var state_1 = _loop_1(l);
            if (typeof state_1 === "object")
                return state_1.value;
        }
        if (d != null) {
            if (d.isError) {
                return new ExcelCalcValue(d.toErrorValue());
            }
            return d;
        }
        return new ExcelCalcValue(new ExcelCalcErrorValue(3));
    };
    UltraCalcFunctionSwitch.prototype.get_name = function () {
        return "switch";
    };
    Object.defineProperty(UltraCalcFunctionSwitch.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionSwitch.prototype.get_minArgs = function () {
        return 3;
    };
    Object.defineProperty(UltraCalcFunctionSwitch.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionSwitch.prototype.get_maxArgs = function () {
        return 0x7FFFFFFF;
    };
    Object.defineProperty(UltraCalcFunctionSwitch.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionSwitch.prototype.doesParameterAllowIntermediateResultArray = function (a, b) {
        return (b == false);
    };
    UltraCalcFunctionSwitch.prototype.get__s = function () {
        return true;
    };
    UltraCalcFunctionSwitch.prototype._v = function (a) {
        if (a % 2 == 1) {
            return true;
        }
        return false;
    };
    UltraCalcFunctionSwitch.$t = markType(UltraCalcFunctionSwitch, 'UltraCalcFunctionSwitch', BuiltInFunctionBase.$);
    return UltraCalcFunctionSwitch;
}(BuiltInFunctionBase));
export { UltraCalcFunctionSwitch };
