/*
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 * as tslib_1 from "tslib";
import { BuiltInFunctionBase } from "./BuiltInFunctionBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { List$1 } from "igniteui-angular-core";
import { StringBuilder } from "igniteui-angular-core";
import { CalcFunctionUtilities } from "./CalcFunctionUtilities";
import { markType } from "igniteui-angular-core";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { ExcelCalcFunction } from "./ExcelCalcFunction";
import { tryParseBool } from "igniteui-angular-core";
/**
 * @hidden
 */
var UltraCalcFunctionTextJoin = /** @class */ (function (_super) {
    tslib_1.__extends(UltraCalcFunctionTextJoin, _super);
    function UltraCalcFunctionTextJoin() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionTextJoin.prototype.evaluate = function (a, b) {
        var c = CalcFunctionUtilities.p(b - 2);
        var d = b - 2;
        var e = new List$1(ExcelCalcValue.$, 2, d);
        for (var f = 0; f < d; f++) {
            e.add(a.pop());
        }
        e.w();
        var g = a.pop();
        var h = a.pop();
        if (h.isError) {
            return new ExcelCalcValue(h.toErrorValue());
        }
        if (g.isError) {
            return new ExcelCalcValue(g.toErrorValue());
        }
        var i;
        if (g.isString) {
            if (!((function () { var j = tryParseBool(g.toString(), i); i = j.p1; return j.ret; })())) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(1));
            }
        }
        else {
            i = g._toBoolean1();
        }
        for (var j = 0; j < e.count; j++) {
            ExcelCalcFunction._ac(c, e._inner[j], i, false);
        }
        var k;
        if ((h.isReference && h.toReference().isEnumerable) || h.isArray || h.isArrayGroup) {
            var l = CalcFunctionUtilities.p(10);
            ExcelCalcFunction._ac(l, h, false, false);
            k = new Array(l.count);
            for (var m = 0; m < k.length; m++) {
                k[m] = l._inner[m].toString();
            }
        }
        else {
            k = new Array(1);
            k[0] = h.toString();
        }
        var n = new StringBuilder(0);
        for (var o = 0; o < c.count; o++) {
            if (o > 0) {
                n.l(k[(o - 1) % k.length]);
            }
            var p = c._inner[o];
            if (p.isError) {
                return new ExcelCalcValue(p.toErrorValue());
            }
            n.l(p.toString());
        }
        if (n.c > 32767) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(1));
        }
        return new ExcelCalcValue(n.toString());
    };
    UltraCalcFunctionTextJoin.prototype.get_name = function () {
        return "textjoin";
    };
    Object.defineProperty(UltraCalcFunctionTextJoin.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionTextJoin.prototype.get_minArgs = function () {
        return 3;
    };
    Object.defineProperty(UltraCalcFunctionTextJoin.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionTextJoin.prototype.get_maxArgs = function () {
        return 0x7FFFFFFF;
    };
    Object.defineProperty(UltraCalcFunctionTextJoin.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionTextJoin.$t = markType(UltraCalcFunctionTextJoin, 'UltraCalcFunctionTextJoin', BuiltInFunctionBase.$);
    return UltraCalcFunctionTextJoin;
}(BuiltInFunctionBase));
export { UltraCalcFunctionTextJoin };
//# sourceMappingURL=UltraCalcFunctionTextJoin.js.map