/*
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 { StringBuilder } from "igniteui-angular-core";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { markType } from "igniteui-angular-core";
import { truncate } from "igniteui-angular-core";
import { stringCreateFromChar } from "igniteui-angular-core";
/**
 * @hidden
 */
var UltraCalcFunctionBase = /** @class */ (function (_super) {
    tslib_1.__extends(UltraCalcFunctionBase, _super);
    function UltraCalcFunctionBase() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionBase.prototype.evaluate = function (a, b) {
        var c = null;
        if (b == 3) {
            c = a.pop();
        }
        var d = a.pop();
        var e = a.pop();
        if (e.isError) {
            return new ExcelCalcValue(e.toErrorValue());
        }
        if (d.isError) {
            return new ExcelCalcValue(d.toErrorValue());
        }
        if (c != null && c.isError) {
            return new ExcelCalcValue(c.toErrorValue());
        }
        var f = e._toInt641();
        var g = d._toInt641();
        var h = c == null ? 1 : c._toInt();
        if (f < 0 || f >= 0x1FFFFFFFFFFFFE) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(4));
        }
        if (g < 2 || g > 36) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(4));
        }
        if (h < 0 || h > 255) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(4));
        }
        var i = new StringBuilder(0);
        var j = g;
        while (f > 0) {
            var k = f % j;
            f -= k;
            var l = void 0;
            if (k < 10) {
                l = String.fromCharCode((48 + k));
            }
            else {
                l = String.fromCharCode((55 + k));
            }
            i.w(0, l);
            f = truncate(Math.floor(f / j));
        }
        if (i.c < h) {
            i.x(0, stringCreateFromChar('0', h - i.c));
        }
        return new ExcelCalcValue(i.toString());
    };
    UltraCalcFunctionBase.prototype.get_maxArgs = function () {
        return 3;
    };
    Object.defineProperty(UltraCalcFunctionBase.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionBase.prototype.get_minArgs = function () {
        return 2;
    };
    Object.defineProperty(UltraCalcFunctionBase.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionBase.prototype.get_name = function () {
        return "base";
    };
    Object.defineProperty(UltraCalcFunctionBase.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionBase.$t = markType(UltraCalcFunctionBase, 'UltraCalcFunctionBase', BuiltInFunctionBase.$);
    return UltraCalcFunctionBase;
}(BuiltInFunctionBase));
export { UltraCalcFunctionBase };
//# sourceMappingURL=UltraCalcFunctionBase.js.map