/*
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 { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { markType } from "igniteui-angular-core";
import { ExcelUtils } from "./ExcelUtils";
import { stringToCharArray } from "igniteui-angular-core";
import { tryParseInt64_2 } from "igniteui-angular-core";
/**
 * @hidden
 */
var UltraCalcFunctionXBase2Dec = /** @class */ (function (_super) {
    tslib_1.__extends(UltraCalcFunctionXBase2Dec, _super);
    function UltraCalcFunctionXBase2Dec() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionXBase2Dec.prototype.evaluate = function (a, b) {
        var _this = this;
        var c = a.pop();
        if (c.isError) {
            return new ExcelCalcValue(c.toErrorValue());
        }
        var d = c.toString();
        if (d.length > this._am) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(4));
        }
        var e;
        var f = ((function () { var g = UltraCalcFunctionXBase2Dec._al(a._w, d, _this._ak, _this._ao, _this._an, e); e = g.p5; return g.ret; })());
        if (null != e) {
            return new ExcelCalcValue(e);
        }
        return new ExcelCalcValue(f);
    };
    UltraCalcFunctionXBase2Dec.prototype.get_minArgs = function () {
        return 1;
    };
    Object.defineProperty(UltraCalcFunctionXBase2Dec.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionXBase2Dec.prototype.get_maxArgs = function () {
        return 1;
    };
    Object.defineProperty(UltraCalcFunctionXBase2Dec.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionXBase2Dec._al = function (a, b, c, d, e, f) {
        f = null;
        b = b.trim();
        var g = 0;
        var h = b.length;
        var i = stringToCharArray(b);
        var j = 1;
        var k = String.fromCharCode(0);
        var _loop_1 = function (l) {
            var m = i[l];
            if (m == '-') {
                return "continue";
            }
            var n;
            var o = ((function () { var p = tryParseInt64_2(m.toString(), 167 | 64, a, n); n = p.p3; return p.ret; })());
            if (o == false) {
                n = m.charCodeAt(0) - 65;
                n += 10;
            }
            if (n >= c) {
                k = m;
                return "continue";
            }
            g += n * j;
            j *= c;
        };
        for (var l = h - 1; l >= 0; l--) {
            _loop_1(l);
        }
        if (0 != k.charCodeAt(0)) {
            f = new ExcelCalcErrorValue(4, ExcelUtils.eg("Error_InvalidNumberSystemDigit", k, b, c));
            return {
                ret: 0,
                p5: f
            };
        }
        if (e < g) {
            g -= (e - d + 1);
        }
        return {
            ret: g,
            p5: f
        };
    };
    UltraCalcFunctionXBase2Dec.prototype.doesParameterAllowIntermediateResultArray = function (a, b) {
        return (b == false);
    };
    UltraCalcFunctionXBase2Dec.$t = markType(UltraCalcFunctionXBase2Dec, 'UltraCalcFunctionXBase2Dec', BuiltInFunctionBase.$);
    return UltraCalcFunctionXBase2Dec;
}(BuiltInFunctionBase));
export { UltraCalcFunctionXBase2Dec };
//# sourceMappingURL=UltraCalcFunctionXBase2Dec.js.map