/*
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 { markType } from "igniteui-angular-core";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
/**
 * @hidden
 */
export let UltraCalcFunctionDecimal = /*@__PURE__*/ (() => {
    class UltraCalcFunctionDecimal extends BuiltInFunctionBase {
        evaluate(a, b) {
            let c = a.pop();
            let d = a.pop();
            if (d.isError) {
                return new ExcelCalcValue(d.toErrorValue());
            }
            if (c.isError) {
                return new ExcelCalcValue(c.toErrorValue());
            }
            let e = d.toString();
            let f = c._toInt641();
            if (e.length > 255) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(1));
            }
            if (f < 2 || f > 36) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(4));
            }
            if (Math.pow(f, e.length) > 0x7FFFFFFFFFFFFFFF) {
                let g = 1;
                let h = 0;
                for (let i = e.length - 1; i >= 0; i--) {
                    let j = e.charAt(i);
                    let k;
                    if ('0'.charCodeAt(0) <= j.charCodeAt(0) && j.charCodeAt(0) <= '9'.charCodeAt(0)) {
                        k = j.charCodeAt(0) - 48;
                    }
                    else if ('a'.charCodeAt(0) <= j.charCodeAt(0) && j.charCodeAt(0) <= 'z'.charCodeAt(0)) {
                        k = j.charCodeAt(0) - 87;
                    }
                    else if ('A'.charCodeAt(0) <= j.charCodeAt(0) && j.charCodeAt(0) <= 'Z'.charCodeAt(0)) {
                        k = j.charCodeAt(0) - 55;
                    }
                    else {
                        k = 0x7FFFFFFF;
                    }
                    if (k > f) {
                        return new ExcelCalcValue(new ExcelCalcErrorValue(4));
                    }
                    h += (g * k);
                    g *= f;
                }
                return new ExcelCalcValue(h);
            }
            else {
                let l = 1;
                let m = 0;
                for (let n = e.length - 1; n >= 0; n--) {
                    let o = e.charAt(n);
                    let p;
                    if ('0'.charCodeAt(0) <= o.charCodeAt(0) && o.charCodeAt(0) <= '9'.charCodeAt(0)) {
                        p = o.charCodeAt(0) - 48;
                    }
                    else if ('a'.charCodeAt(0) <= o.charCodeAt(0) && o.charCodeAt(0) <= 'z'.charCodeAt(0)) {
                        p = o.charCodeAt(0) - 87;
                    }
                    else if ('A'.charCodeAt(0) <= o.charCodeAt(0) && o.charCodeAt(0) <= 'Z'.charCodeAt(0)) {
                        p = o.charCodeAt(0) - 55;
                    }
                    else {
                        p = 0x7FFFFFFF;
                    }
                    if (p > f) {
                        return new ExcelCalcValue(new ExcelCalcErrorValue(4));
                    }
                    m += (l * p);
                    l *= f;
                }
                return new ExcelCalcValue(m);
            }
        }
        get_maxArgs() {
            return 2;
        }
        get maxArgs() {
            return this.get_maxArgs();
        }
        get_minArgs() {
            return 2;
        }
        get minArgs() {
            return this.get_minArgs();
        }
        get_name() {
            return "decimal";
        }
        get name() {
            return this.get_name();
        }
    }
    UltraCalcFunctionDecimal.$t = markType(UltraCalcFunctionDecimal, 'UltraCalcFunctionDecimal', BuiltInFunctionBase.$);
    return UltraCalcFunctionDecimal;
})();
