/*
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 { List$1 } from "igniteui-angular-core";
import { markType } from "igniteui-angular-core";
import { StringUtilities } from "./StringUtilities";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
/**
 * @hidden
 */
export class UltraCalcFunctionSwitch extends BuiltInFunctionBase {
    evaluate(a, b) {
        let c = new List$1(ExcelCalcValue.$, 0);
        let d = null;
        if (b % 2 == 0) {
            d = a.pop();
            b--;
        }
        while (b > 1) {
            c.add(a.pop());
            b--;
        }
        let e = a.pop();
        if (e.isError) {
            return new ExcelCalcValue(e.toErrorValue());
        }
        let f, g, h, i;
        f = g = h = i = false;
        let 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 {
            let k = e._toDouble3();
            j = k;
            if (k == 0) {
                f = true;
            }
            else {
                i = true;
            }
        }
        for (let l = c.count - 1; l > 0; l -= 2) {
            let m = c._inner[l];
            let n = c._inner[l - 1];
            if (m.isError) {
                return new ExcelCalcValue(m.toErrorValue());
            }
            let o = false;
            if (f || i) {
                if (!m.isString && !m.isBoolean) {
                    if (m.isNull) {
                        o = f;
                    }
                    else {
                        let p;
                        if (((() => { let q = m._toDouble1(p); p = q.p0; return q.ret; })())) {
                            if (f) {
                                o = p == 0;
                            }
                            else {
                                o = p == 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 n;
            }
        }
        if (d != null) {
            if (d.isError) {
                return new ExcelCalcValue(d.toErrorValue());
            }
            return d;
        }
        return new ExcelCalcValue(new ExcelCalcErrorValue(3));
    }
    get_name() {
        return "switch";
    }
    get name() {
        return this.get_name();
    }
    get_minArgs() {
        return 3;
    }
    get minArgs() {
        return this.get_minArgs();
    }
    get_maxArgs() {
        return 0x7FFFFFFF;
    }
    get maxArgs() {
        return this.get_maxArgs();
    }
    doesParameterAllowIntermediateResultArray(a, b) {
        return (b == false);
    }
    get__s() {
        return true;
    }
    _v(a) {
        if (a % 2 == 1) {
            return true;
        }
        return false;
    }
}
UltraCalcFunctionSwitch.$t = markType(UltraCalcFunctionSwitch, 'UltraCalcFunctionSwitch', BuiltInFunctionBase.$);
//# sourceMappingURL=UltraCalcFunctionSwitch.js.map