/*
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 { Base, Number_$type, fromEnum, markType } from "igniteui-angular-core";
import { BindingFormatter } from "igniteui-angular-core";
import { NumberFormatSpecifier } from "igniteui-angular-core";
import { Dictionary$2 } from "igniteui-angular-core";
import { DataAbbreviation } from "./DataAbbreviation";
import { DataAbbreviationMode_$type } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { truncate, isNaN_, isInfinity } from "igniteui-angular-core";
import { stringContains, stringIsNullOrEmpty, stringToCharArray } from "igniteui-angular-core";
import { padRight, stringFormat, trimEnd } from "igniteui-angular-core";
import { round10N } from "igniteui-angular-core";
/**
 * @hidden
 */
export let DataAbbreviator = /*@__PURE__*/ (() => {
    class DataAbbreviator extends Base {
        static p(a, b, c) {
            if (!DataAbbreviator.e.containsKey(c)) {
                let d = new BindingFormatter();
                d.j = "{0}";
                d.d = [((() => {
                        let $ret = new NumberFormatSpecifier();
                        $ret.locale = "en-US";
                        $ret.useGrouping = false;
                        $ret.maximumFractionDigits = c;
                        return $ret;
                    })())];
                DataAbbreviator.e.item(c, d);
            }
            let e = DataAbbreviator.e.item(c);
            let f = e.i(a);
            if (stringContains(f, ",")) {
                f = f.split(',')[1];
            }
            else if (stringContains(f, ".")) {
                f = f.split('.')[1];
            }
            else {
                f = "";
            }
            if (b != -1 && f.length < b) {
                f = padRight(f, f.length + b, '0');
            }
            if (c != -1 && f.length > c) {
                f = f.substr(0, c);
            }
            return f;
        }
        static o(a) {
            let b = stringFormat("0:0.0", a);
            if (stringContains(b, ",")) {
                return ",";
            }
            return ".";
        }
        static r(a) {
            let b = Math.floor(a);
            let c = stringFormat("{0}", b);
            return c;
        }
        static b(a, b, c, d) {
            let e = new DataAbbreviation();
            e.a = d;
            e.c = DataAbbreviator.l(d);
            e.l = DataAbbreviator.q(d);
            e.g = a;
            e.k = (e.g).toString();
            e.d = (e.g / e.c);
            if (c == -1 && d != 0 && d != 1 && d != 9 && d != 8) {
                c = 2;
                e.d = round10N(e.d, 2);
            }
            else if (c == -1) {
                c = 5;
                e.d = round10N(e.d, 5);
            }
            let f = DataAbbreviator.o(e.d);
            if (b < 0 && c < 0) {
                e.f = truncate(Math.floor(e.d));
                e.e = e.d - e.f;
                e.n = DataAbbreviator.r(e.d);
                e.j = trimEnd(DataAbbreviator.p(e.d, b, c), '0');
                e.i = DataAbbreviator.n(e.j);
                e.h = DataAbbreviator.m(e.j);
                e.m = e.n;
                if (!stringIsNullOrEmpty(e.j)) {
                    e.m += f + e.j;
                }
            }
            else if (b >= 0) {
                if (c >= b) {
                    e.d = round10N(e.d, c);
                }
                e.f = truncate(Math.floor(e.d));
                e.e = e.d - e.f;
                e.n = DataAbbreviator.r(e.d);
                e.j = DataAbbreviator.p(e.d, b, c);
                e.m = e.n;
                if (!stringIsNullOrEmpty(e.j)) {
                    let g = Math.max(b, trimEnd(e.j, '0').length);
                    g = Math.min(g, e.j.length);
                    e.j = e.j.substr(0, g);
                    e.m += f + e.j;
                    e.i = e.j.length;
                    e.h = e.j.length;
                }
                else {
                    e.i = 0;
                    e.h = -1;
                }
            }
            else if (c >= 0) {
                e.d = round10N(e.d, c);
                e.f = truncate(Math.floor(e.d));
                e.e = e.d - e.f;
                e.n = DataAbbreviator.r(e.d);
                e.j = trimEnd(DataAbbreviator.p(e.d, b, c), '0');
                e.i = DataAbbreviator.n(e.j);
                e.h = DataAbbreviator.m(e.j);
                e.m = e.n;
                if (!stringIsNullOrEmpty(e.j)) {
                    e.m += f + e.j;
                }
            }
            return e;
        }
        static s() {
            if (DataAbbreviator.k == null) {
                DataAbbreviator.k = ((() => {
                    let $ret = new List$1(DataAbbreviation.$, 0);
                    $ret.add(((() => {
                        let $ret = new DataAbbreviation();
                        $ret.a = 7;
                        $ret.l = "Q";
                        $ret.c = 1E+15;
                        return $ret;
                    })()));
                    $ret.add(((() => {
                        let $ret = new DataAbbreviation();
                        $ret.a = 6;
                        $ret.l = "T";
                        $ret.c = 1000000000000;
                        return $ret;
                    })()));
                    $ret.add(((() => {
                        let $ret = new DataAbbreviation();
                        $ret.a = 5;
                        $ret.l = "B";
                        $ret.c = 1000000000;
                        return $ret;
                    })()));
                    $ret.add(((() => {
                        let $ret = new DataAbbreviation();
                        $ret.a = 4;
                        $ret.l = "M";
                        $ret.c = 1000000;
                        return $ret;
                    })()));
                    $ret.add(((() => {
                        let $ret = new DataAbbreviation();
                        $ret.a = 3;
                        $ret.l = "K";
                        $ret.c = 1000;
                        return $ret;
                    })()));
                    $ret.add(((() => {
                        let $ret = new DataAbbreviation();
                        $ret.a = 9;
                        $ret.l = "";
                        $ret.c = 1;
                        return $ret;
                    })()));
                    return $ret;
                })());
                DataAbbreviator.f = new Dictionary$2(DataAbbreviationMode_$type, DataAbbreviation.$, 0);
                for (let a of fromEnum(DataAbbreviator.k)) {
                    DataAbbreviator.f.addItem(a.a, a);
                }
            }
        }
        static l(a) {
            if (DataAbbreviator.f.containsKey(a)) {
                return DataAbbreviator.f.item(a).c;
            }
            return 1;
        }
        static q(a) {
            if (DataAbbreviator.f.containsKey(a)) {
                return DataAbbreviator.f.item(a).l;
            }
            return "";
        }
        static a(a, b, c, d) {
            let e = [a];
            let f = DataAbbreviator.h(e, b, c, d);
            return f._inner[0];
        }
        static h(a, b, c = -1, d = -1) {
            DataAbbreviator.s();
            if (c > d) {
                d = c;
            }
            let e = b;
            if (e == 8 || e == 0) {
                e = 2;
            }
            if (e == 9) {
                return DataAbbreviator.i(a, c, d);
            }
            else if (e == 1) {
                return DataAbbreviator.g(a, c, d);
            }
            else if (e == 2) {
                e = DataAbbreviator.d(a);
            }
            if (e == 9 || e == 3 || e == 4 || e == 5 || e == 6 || e == 7) {
                return DataAbbreviator.j(e, a, c, d);
            }
            return DataAbbreviator.i(a, c, d);
        }
        static j(a, b, c = -1, d = -1) {
            let e = new List$1(DataAbbreviation.$, 0);
            for (let f = 0; f < b.length; f++) {
                let g = b[f];
                if (isNaN_(g) || isInfinity(g) || !DataAbbreviator.f.containsKey(a)) {
                    e.add(new DataAbbreviation());
                }
                else {
                    let h = DataAbbreviator.b(g, c, d, a);
                    e.add(h);
                }
            }
            let i = c;
            let j = d;
            if (i < 0 || j < 0) {
                for (let k of fromEnum(e)) {
                    i = Math.max(i, k.i);
                    j = Math.max(j, k.h);
                }
                if (j > i) {
                    i = j;
                }
            }
            for (let l = 0; l < e.count; l++) {
                if (e._inner[l].b()) {
                    let m = e._inner[l].g;
                    let n = DataAbbreviator.b(m, i, j, a);
                    e._inner[l] = n;
                }
            }
            return e;
        }
        static g(a, b, c) {
            DataAbbreviator.s();
            let d = new List$1(DataAbbreviation.$, 0);
            for (let e = 0; e < a.length; e++) {
                let f = a[e];
                if (isNaN_(f) || isInfinity(f)) {
                    d.add(new DataAbbreviation());
                }
                else {
                    let g = DataAbbreviator.c(f);
                    let h = DataAbbreviator.b(f, b, c, g);
                    d.add(h);
                }
            }
            return d;
        }
        static i(a, b = -1, c = -1) {
            let d = new List$1(DataAbbreviation.$, 0);
            for (let e = 0; e < a.length; e++) {
                let f = a[e];
                if (isNaN_(f) || isInfinity(f)) {
                    d.add(new DataAbbreviation());
                }
                else {
                    let g = DataAbbreviator.b(f, b, c, 9);
                    d.add(g);
                    DataAbbreviator.t("abbr.N min=" + g.i + " max=" + g.h + " abbr=" + g.m + g.l + "         for " + f);
                }
            }
            return d;
        }
        static m(a) {
            let b = stringToCharArray(a);
            if (stringContains(a, ".")) {
                b = stringToCharArray(a.split('.')[1]);
            }
            for (let c = b.length - 1; c >= 0; c--) {
                if (b[c] != '0') {
                    return c + 1;
                }
            }
            return -1;
        }
        static n(a) {
            let b = stringToCharArray(a);
            if (stringContains(a, ".")) {
                b = stringToCharArray(a.split('.')[1]);
            }
            for (let c = 0; c < b.length; c++) {
                if (b[c] != '0') {
                    return c + 1;
                }
            }
            return 0;
        }
        static d(a) {
            let b = DataAbbreviator.g(a, -1, -1);
            b.aa((c, d) => {
                if (c.c < d.c) {
                    return -1;
                }
                if (c.c > d.c) {
                    return 1;
                }
                return 0;
            });
            let c = truncate(Math.floor(b.count / 2));
            let d = b._inner[c];
            return d.a;
        }
        static c(a) {
            if (isNaN_(a) || isInfinity(a)) {
                return 9;
            }
            let b = Math.abs(a);
            for (let c = 0; c < DataAbbreviator.k.count; c++) {
                let d = DataAbbreviator.k._inner[c];
                if (b >= d.c || c == DataAbbreviator.k.count - 1) {
                    return d.a;
                }
            }
            return 9;
        }
        static t(message_) {
        }
    }
    DataAbbreviator.$t = markType(DataAbbreviator, 'DataAbbreviator');
    DataAbbreviator.k = null;
    DataAbbreviator.f = null;
    DataAbbreviator.e = new Dictionary$2(Number_$type, BindingFormatter.$, 0);
    return DataAbbreviator;
})();
