/*
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 { Base, markType } from "igniteui-webcomponents-core";
import { isNaN_ } from "igniteui-webcomponents-core";
import { isDigit } from "igniteui-webcomponents-core";
import { stringIsNullOrEmpty } from "igniteui-webcomponents-core";
/**
 * @hidden
 */
var NumericCellFormatter = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(NumericCellFormatter, _super);
    function NumericCellFormatter() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    NumericCellFormatter.c = function () {
        if (NumericCellFormatter.a != null) {
            return NumericCellFormatter.a;
        }
        var a = "";
        var b = 1.1;
        var c = b.toLocaleString();
        var d = false;
        for (var e = 0; e < c.length; e++) {
            if (c.charAt(e) == '1') {
                d = !d;
            }
            if (c.charAt(e) != '1' && d) {
                a += c.charAt(e);
            }
        }
        NumericCellFormatter.a = a;
        return NumericCellFormatter.a;
    };
    NumericCellFormatter.b = function (a) {
        if (a.ky != null) {
            return a.ky.i(a.k5);
        }
        var b = a.k5;
        var c = a.k5;
        var d = 10;
        var e = 0;
        var f = "0";
        if (isNaN_(a.k5)) {
            return "";
        }
        var g = 0;
        if (a.k5 >= 0) {
            g = a.k5 - Math.floor(a.k5);
        }
        else {
            g = Math.abs(a.k5 - Math.ceil(a.k5));
        }
        var h = 0;
        if (a.k5 >= 0) {
            h = a.k5 - g;
        }
        else {
            h = a.k5 + g;
        }
        var i = Math.abs(h);
        var j = g.toString();
        if (g == 0) {
            j = "";
        }
        else {
            j = j.substr(2);
        }
        var k = Math.round(i).toString();
        d = a.ld;
        e = a.lf;
        if (e < 0) {
            e = 0;
        }
        if (d < 0) {
            d = 10;
        }
        if (e > d) {
            d = e;
        }
        if (j.length > d) {
            var l = Math.round(g * (Math.pow(10, d))) / (Math.pow(10, d));
            j = (l).toString();
            if (l == 1) {
                if (a.k5 >= 0) {
                    h += 1;
                    i += 1;
                }
                else {
                    h -= 1;
                    i += 1;
                }
                j = "";
                k = Math.round(i).toString();
            }
            else if (l == 0) {
                j = "";
            }
            else {
                j = j.substr(2);
            }
        }
        var m = k.length;
        var n = Math.max(0, a.lh - k.length);
        var o = Math.max(0, a.lf - j.length);
        var p = false;
        if (k.charAt(0) == '1') {
            p = true;
        }
        for (var q = 0; q < n; q++) {
            var r = "0";
            if (a.k3) {
                if (p) {
                    r = "9";
                }
                else {
                    r = "1";
                }
            }
            k = r + k;
        }
        for (var s = 0; s < o; s++) {
            j = j + "0";
        }
        if (d == 0) {
            j = "";
        }
        if (a.k3 && k.length > 0) {
            var t = parseInt(k);
            var u = t.toLocaleString();
            var v = '1';
            if (p) {
                v = '9';
            }
            var w = true;
            var x = "";
            for (var y = 0; y < u.length; y++) {
                if (u.charAt(y) == v && w) {
                    x += "0";
                }
                else {
                    x += u.charAt(y);
                    if (isDigit(u.charAt(y)) && u.charAt(y) != v) {
                        w = false;
                    }
                }
            }
            k = x;
        }
        if (h < 0) {
            k = "-" + k;
        }
        var z = k;
        if (j.length > 0) {
            z += NumericCellFormatter.c() + j;
        }
        if (b >= 0) {
            if (!stringIsNullOrEmpty(a.ma)) {
                z = a.ma + z;
            }
            if (!stringIsNullOrEmpty(a.mc)) {
                z += a.mc;
            }
        }
        else {
            if (!stringIsNullOrEmpty(a.l5)) {
                z = a.l5 + z;
            }
            if (!stringIsNullOrEmpty(a.l7)) {
                z += a.l7;
            }
        }
        return z;
    };
    NumericCellFormatter.$t = markType(NumericCellFormatter, 'NumericCellFormatter');
    NumericCellFormatter.a = null;
    return NumericCellFormatter;
}(Base));
export { NumericCellFormatter };
//# sourceMappingURL=NumericCellFormatter.js.map
