/*
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, typeCast, Number_$type, markType } from "igniteui-angular-core";
import { Brush } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
import { LinearGradientBrush } from "igniteui-angular-core";
import { ColorUtil } from "igniteui-angular-core";
import { Thickness } from "igniteui-angular-core";
import { Axis } from "./Axis";
import { ScalerParams } from "./ScalerParams";
import { List$1 } from "igniteui-angular-core";
import { Dictionary$2 } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { AxisAnnotation } from "./AxisAnnotation";
import { HashSet$1 } from "igniteui-angular-core";
import { truncate, log10 } from "igniteui-angular-core";
import { round10N } from "igniteui-angular-core";
/**
 * @hidden
 */
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].cf) {
                u = s[v];
            }
            else {
                t = s[v];
            }
        }
        var w = Color.u(255, 102, 102, 102);
        var x = Color.u(255, 255, 255, 255);
        if (t != null) {
            var y = new ScalerParams(1, d.mq, t.i1, t.b8);
            y.c = e;
            var z = t.dz(b.x, y);
            a.p.add(z);
            a.o.add(z);
            if (g != null) {
                a.g.add(g);
            }
            else {
                a.g.add(f);
            }
            if (h != null) {
                a.n.add(h);
            }
            else {
                a.n.add(AxisAnnotationFrameManager.e(a.g._inner[a.g.count - 1], w, x));
            }
            a.j.add(j.left);
            a.l.add(j.top);
            a.k.add(j.right);
            a.i.add(j.bottom);
            if (k != null) {
                a.m.add(k);
            }
            else {
                a.m.add(NaN);
            }
            if (i != null) {
                a.h.add(i);
            }
            else {
                a.h.add(null);
            }
            if (q) {
                a.f.add(t);
            }
            else {
                a.f.add(null);
            }
        }
        if (u != null) {
            var aa = new ScalerParams(1, d.mq, u.i1, u.b8);
            aa.c = e;
            var ab = u.dz(b.y, aa);
            a.aa.add(ab);
            a.z.add(ab);
            if (l != null) {
                a.r.add(l);
            }
            else {
                a.r.add(f);
            }
            if (m != null) {
                a.y.add(m);
            }
            else {
                a.y.add(AxisAnnotationFrameManager.e(a.r._inner[a.r.count - 1], w, x));
            }
            a.u.add(o.left);
            a.w.add(o.top);
            a.v.add(o.right);
            a.t.add(o.bottom);
            if (p != null) {
                a.x.add(p);
            }
            else {
                a.x.add(NaN);
            }
            if (n != null) {
                a.s.add(n);
            }
            else {
                a.s.add(null);
            }
            if (r) {
                a.q.add(u);
            }
            else {
                a.q.add(null);
            }
        }
    };
    AxisAnnotationFrameManager.b = function (a) {
        a.f.clear();
        a.q.clear();
        a.p.clear();
        a.aa.clear();
        a.o.clear();
        a.z.clear();
        a.g.clear();
        a.h.clear();
        a.j.clear();
        a.l.clear();
        a.k.clear();
        a.i.clear();
        a.m.clear();
        a.n.clear();
        a.r.clear();
        a.s.clear();
        a.u.clear();
        a.w.clear();
        a.v.clear();
        a.t.clear();
        a.x.clear();
        a.y.clear();
    };
    AxisAnnotationFrameManager.a = function (a, b, c) {
        if (!b.ca) {
            return a;
        }
        var d = 0;
        if (c >= 0) {
            d = c;
        }
        else {
            var e = b.d7();
            d = e == 0 ? 0 : truncate(Math.max(-Math.floor(log10(e)), 0));
            d += 1;
        }
        return round10N(a, d);
    };
    AxisAnnotationFrameManager.d = function (a, b, c, d, e, f, g, h, i, j) {
        var k = new List$1(Axis.$, 0);
        var l = new HashSet$1(Axis.$, 0);
        var m = new Dictionary$2(Axis.$, Number_$type, 0);
        var _loop_1 = function (n) {
            var o = b.f._inner[n];
            if (o != null) {
                if (!l.contains(o)) {
                    k.add(o);
                    m.item(o, 0);
                    l.add_1(o);
                }
                var p = void 0;
                if (!d.containsKey(o)) {
                    p = new Pool$1(AxisAnnotation.$);
                    p.create = function () { return new AxisAnnotation(); };
                    p.destroy = function (q) {
                    };
                    p.activate = function (q) { return o.al.add(q); };
                    p.disactivate = function (q) { return o.al.remove(q); };
                    d.item(o, p);
                    e.add(o);
                }
                else {
                    p = d.item(o);
                }
                var q = p.item(m.item(o));
                m.item(o, m.item(o) + 1);
                q.j = false;
                q.value = b.o._inner[n];
                var r = b.p._inner[n];
                if (i != null) {
                    var s = i(r);
                    q.text = s;
                }
                else {
                    r = AxisAnnotationFrameManager.a(r, o, g);
                    q.text = o.fj(r);
                }
                q.textColor = b.n._inner[n];
                q.background = b.g._inner[n];
                q.backgroundPadding = new Thickness(1, b.j._inner[n], b.l._inner[n], b.k._inner[n], b.i._inner[n]);
                q.outline = b.h._inner[n];
                q.strokeThickness = b.m._inner[n];
                if (q.j) {
                    q.j = false;
                    c = true;
                }
            }
        };
        for (var n = 0; n < b.p.count; n++) {
            _loop_1(n);
        }
        var _loop_2 = function (t) {
            var u = b.q._inner[t];
            if (u != null) {
                if (!l.contains(u)) {
                    k.add(u);
                    m.item(u, 0);
                    l.add_1(u);
                }
                var v = void 0;
                if (!d.containsKey(u)) {
                    v = new Pool$1(AxisAnnotation.$);
                    v.create = function () { return new AxisAnnotation(); };
                    v.destroy = function (w) {
                    };
                    v.activate = function (w) { return u.al.add(w); };
                    v.disactivate = function (w) { return u.al.remove(w); };
                    d.item(u, v);
                    e.add(u);
                }
                else {
                    v = d.item(u);
                }
                var w = v.item(m.item(u));
                m.item(u, m.item(u) + 1);
                w.j = false;
                var x = b.aa._inner[t];
                w.value = b.z._inner[t];
                if (j != null) {
                    var y = j(x);
                    w.text = y;
                }
                else {
                    x = AxisAnnotationFrameManager.a(x, u, h);
                    w.text = u.fj(x);
                }
                w.textColor = b.y._inner[t];
                w.background = b.r._inner[t];
                w.backgroundPadding = new Thickness(1, b.u._inner[t], b.w._inner[t], b.v._inner[t], b.t._inner[t]);
                w.outline = b.s._inner[t];
                w.strokeThickness = b.x._inner[t];
                if (w.j) {
                    w.j = false;
                    c = true;
                }
            }
        };
        for (var t = 0; t < b.aa.count; t++) {
            _loop_2(t);
        }
        for (var z = 0; z < k.count; z++) {
            if (d.containsKey(k._inner[z])) {
                var aa = d.item(k._inner[z]);
                aa.count = m.item(k._inner[z]);
            }
        }
        for (var ab = e.count - 1; ab >= 0; ab--) {
            if (!l.contains(e._inner[ab])) {
                c = true;
                var ac = d.item(e._inner[ab]);
                ac.count = 0;
                ac.activate = null;
                ac.create = null;
                ac.destroy = null;
                ac.disactivate = null;
                d.removeItem(e._inner[ab]);
                e.removeAt(ab);
            }
        }
        if (c && f) {
            for (var ad = 0; ad < k.count; ad++) {
                var ae = k._inner[ad];
                if (ae.a3.c) {
                    ae.gk(true);
                    ae.a3.c = false;
                }
            }
        }
    };
    AxisAnnotationFrameManager.$t = markType(AxisAnnotationFrameManager, 'AxisAnnotationFrameManager');
    return AxisAnnotationFrameManager;
}(Base));
export { AxisAnnotationFrameManager };
//# sourceMappingURL=AxisAnnotationFrameManager.js.map