/*
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 { Brush } from "igniteui-react-core/ES5/Brush";
import { Color } from "igniteui-react-core/ES5/Color";
import { LinearGradientBrush } from "igniteui-react-core/ES5/LinearGradientBrush";
import { ColorUtil } from "igniteui-react-core/ES5/ColorUtil";
import { Base, typeCast, Number_$type, markType } from "igniteui-react-core/ES5/type";
import { Axis } from "./Axis";
import { ScalerParams } from "./ScalerParams";
import { List$1 } from "igniteui-react-core/ES5/List$1";
import { Dictionary$2 } from "igniteui-react-core/ES5/Dictionary$2";
import { Pool$1 } from "igniteui-react-core/ES5/Pool$1";
import { AxisAnnotation } from "./AxisAnnotation";
import { HashSet$1 } from "igniteui-react-core/ES5/HashSet$1";
import { truncate, log10 } from "igniteui-react-core/ES5/number";
import { round10N } from "igniteui-react-core/ES5/numberExtended";
var AxisAnnotationFrameManager = /** @class */ (function (_super) {
    tslib_1.__extends(AxisAnnotationFrameManager, _super);
    function AxisAnnotationFrameManager() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    AxisAnnotationFrameManager.e = function (a, b, c) {
        var d = new Color();
        if (typeCast(LinearGradientBrush.$, a) !== null) {
            if (a.gradientStops == null || a.gradientStops.length < 1) {
                var e = new Brush();
                e.color = b;
                return e;
            }
            d = a.gradientStops[0].color;
        }
        else {
            d = a.color;
        }
        var f = ColorUtil.a(d);
        var g = ColorUtil.a(c);
        var h = ColorUtil.a(b);
        var i = (f[3] + 0.05) / (h[3] + 0.05);
        var j = (g[3] + 0.05) / (f[3] + 0.05);
        if (i > j) {
            var k = new Brush();
            k.color = b;
        }
        var l = new Brush();
        l.color = c;
        return l;
    };
    AxisAnnotationFrameManager.c = function (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) {
        var s = c.ag();
        var t = null;
        var u = null;
        for (var v = 0; v < s.length; v++) {
            if (s[v].ce) {
                u = s[v];
            }
            else {
                t = s[v];
            }
        }
        if (t != null && u != null) {
            var w = new ScalerParams(1, d.mk, t.it, t.b8);
            w.c = e;
            var x = new ScalerParams(1, d.mk, u.it, u.b8);
            x.c = e;
            var y = t.dw(b.x, w);
            var z = u.dw(b.y, x);
            var aa = Color.u(255, 102, 102, 102);
            var ab = Color.u(255, 255, 255, 255);
            a.m.add(y);
            a.u.add(z);
            a.l.add(y);
            a.t.add(z);
            if (g != null) {
                a.g.add(g);
            }
            else {
                a.g.add(f);
            }
            if (l != null) {
                a.o.add(l);
            }
            else {
                a.o.add(f);
            }
            if (h != null) {
                a.k.add(h);
            }
            else {
                a.k.add(AxisAnnotationFrameManager.e(a.g._inner[a.g.count - 1], aa, ab));
            }
            if (m != null) {
                a.s.add(m);
            }
            else {
                a.s.add(AxisAnnotationFrameManager.e(a.g._inner[a.g.count - 1], aa, ab));
            }
            if (j != null) {
                a.i.add(j);
            }
            else {
                a.i.add(NaN);
            }
            if (o != null) {
                a.q.add(o);
            }
            else {
                a.q.add(NaN);
            }
            if (k != null) {
                a.j.add(k);
            }
            else {
                a.j.add(NaN);
            }
            if (p != null) {
                a.r.add(p);
            }
            else {
                a.r.add(NaN);
            }
            if (i != null) {
                a.h.add(i);
            }
            else {
                a.h.add(null);
            }
            if (n != null) {
                a.p.add(n);
            }
            else {
                a.p.add(null);
            }
            if (r) {
                a.n.add(u);
            }
            else {
                a.n.add(null);
            }
            if (q) {
                a.f.add(t);
            }
            else {
                a.f.add(null);
            }
        }
    };
    AxisAnnotationFrameManager.b = function (a) {
        a.f.clear();
        a.n.clear();
        a.m.clear();
        a.u.clear();
        a.l.clear();
        a.t.clear();
        a.g.clear();
        a.h.clear();
        a.i.clear();
        a.j.clear();
        a.k.clear();
        a.o.clear();
        a.p.clear();
        a.q.clear();
        a.r.clear();
        a.s.clear();
    };
    AxisAnnotationFrameManager.a = function (a, b, c) {
        if (!b.ca) {
            return a;
        }
        var d = 0;
        if (c >= 0) {
            d = c;
        }
        else {
            var e = b.d4();
            d = truncate(Math.max(-Math.floor(log10(e)), 0));
            d += 1;
        }
        return round10N(a, d);
    };
    AxisAnnotationFrameManager.d = function (a, b, c, d, e, f, g) {
        var h = new List$1(Axis.$, 0);
        var i = new HashSet$1(Axis.$, 0);
        var j = new Dictionary$2(Axis.$, Number_$type, 0);
        var _loop_1 = function (k) {
            var l = a.f._inner[k];
            if (l != null) {
                if (!i.contains(l)) {
                    h.add(l);
                    j.item(l, 0);
                    i.add_1(l);
                }
                var m = void 0;
                if (!c.containsKey(l)) {
                    m = new Pool$1(AxisAnnotation.$);
                    m.create = function () { return new AxisAnnotation(); };
                    m.destroy = function (n) {
                    };
                    m.activate = function (n) { return l.al.add(n); };
                    m.disactivate = function (n) { return l.al.remove(n); };
                    c.item(l, m);
                    d.add(l);
                }
                else {
                    m = c.item(l);
                }
                var n = m.item(j.item(l));
                j.item(l, j.item(l) + 1);
                n.j = false;
                n.value = a.l._inner[k];
                var o = a.m._inner[k];
                o = AxisAnnotationFrameManager.a(o, l, f);
                n.text = l.fd(o);
                n.textColor = a.k._inner[k];
                n.background = a.g._inner[k];
                n.backgroundPadding = a.i._inner[k];
                n.outline = a.h._inner[k];
                n.strokeThickness = a.j._inner[k];
                if (n.j) {
                    n.j = false;
                    b = true;
                }
            }
            var p = a.n._inner[k];
            if (p != null) {
                if (!i.contains(p)) {
                    h.add(p);
                    j.item(p, 0);
                    i.add_1(p);
                }
                var q = void 0;
                if (!c.containsKey(p)) {
                    q = new Pool$1(AxisAnnotation.$);
                    q.create = function () { return new AxisAnnotation(); };
                    q.destroy = function (r) {
                    };
                    q.activate = function (r) { return p.al.add(r); };
                    q.disactivate = function (r) { return p.al.remove(r); };
                    c.item(p, q);
                    d.add(p);
                }
                else {
                    q = c.item(p);
                }
                var r = q.item(j.item(p));
                j.item(p, j.item(p) + 1);
                r.j = false;
                var s = a.u._inner[k];
                s = AxisAnnotationFrameManager.a(s, p, g);
                r.value = a.t._inner[k];
                r.text = p.fd(s);
                r.textColor = a.s._inner[k];
                r.background = a.o._inner[k];
                r.backgroundPadding = a.q._inner[k];
                r.outline = a.p._inner[k];
                r.strokeThickness = a.r._inner[k];
                if (r.j) {
                    r.j = false;
                    b = true;
                }
            }
        };
        for (var k = 0; k < a.m.count; k++) {
            _loop_1(k);
        }
        for (var t = 0; t < h.count; t++) {
            if (c.containsKey(h._inner[t])) {
                var u = c.item(h._inner[t]);
                u.count = j.item(h._inner[t]);
            }
        }
        for (var v = d.count - 1; v >= 0; v--) {
            if (!i.contains(d._inner[v])) {
                b = true;
                var w = c.item(d._inner[v]);
                w.count = 0;
                w.activate = null;
                w.create = null;
                w.destroy = null;
                w.disactivate = null;
                c.removeItem(d._inner[v]);
                d.removeAt(v);
            }
        }
        if (b && e) {
            for (var x = 0; x < h.count; x++) {
                var y = h._inner[x];
                if (y.a3.c) {
                    y.gd(true);
                    y.a3.c = false;
                }
            }
        }
    };
    AxisAnnotationFrameManager.$t = markType(AxisAnnotationFrameManager, 'AxisAnnotationFrameManager');
    return AxisAnnotationFrameManager;
}(Base));
export { AxisAnnotationFrameManager };
