/*
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 { __extends } 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, isNaN_, log10 } from "igniteui-angular-core";
import { round10N } from "igniteui-angular-core";
/**
 * @hidden
 */
var AxisAnnotationFrameManager = /** @class */ /*@__PURE__*/ (function (_super) {
    __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, s, t) {
        var u = c.ag();
        var v = null;
        var w = null;
        for (var x = 0; x < u.length; x++) {
            if (u[x].co) {
                w = u[x];
            }
            else {
                v = u[x];
            }
        }
        var y = Color.u(255, 102, 102, 102);
        var z = Color.u(255, 255, 255, 255);
        if (v != null) {
            var aa = new ScalerParams(1, d.sf, v.kc, v.cg);
            aa.c = e;
            var ab = v.el(b.x, aa);
            a.q.add(ab);
            a.p.add(ab);
            if (g != null) {
                a.h.add(g);
            }
            else {
                a.h.add(f);
            }
            a.g.add(h);
            if (i != null) {
                a.o.add(i);
            }
            else {
                a.o.add(AxisAnnotationFrameManager.e(a.h._inner[a.h.count - 1], y, z));
            }
            a.k.add(k.left);
            a.m.add(k.top);
            a.l.add(k.right);
            a.j.add(k.bottom);
            if (!isNaN_(l)) {
                a.n.add(l);
            }
            else {
                a.n.add(NaN);
            }
            if (j != null) {
                a.i.add(j);
            }
            else {
                a.i.add(null);
            }
            if (s) {
                a.f.add(v);
            }
            else {
                a.f.add(null);
            }
        }
        if (w != null) {
            var ac = new ScalerParams(1, d.sf, w.kc, w.cg);
            ac.c = e;
            var ad = w.el(b.y, ac);
            a.ac.add(ad);
            a.ab.add(ad);
            if (m != null) {
                a.t.add(m);
            }
            else {
                a.t.add(f);
            }
            a.s.add(n);
            if (o != null) {
                a.aa.add(o);
            }
            else {
                a.aa.add(AxisAnnotationFrameManager.e(a.t._inner[a.t.count - 1], y, z));
            }
            a.w.add(q.left);
            a.y.add(q.top);
            a.x.add(q.right);
            a.v.add(q.bottom);
            if (!isNaN_(r)) {
                a.z.add(r);
            }
            else {
                a.z.add(NaN);
            }
            if (p != null) {
                a.u.add(p);
            }
            else {
                a.u.add(null);
            }
            if (t) {
                a.r.add(w);
            }
            else {
                a.r.add(null);
            }
        }
    };
    AxisAnnotationFrameManager.b = function (a) {
        a.f.clear();
        a.r.clear();
        a.q.clear();
        a.ac.clear();
        a.p.clear();
        a.ab.clear();
        a.h.clear();
        a.g.clear();
        a.i.clear();
        a.k.clear();
        a.m.clear();
        a.l.clear();
        a.j.clear();
        a.n.clear();
        a.o.clear();
        a.t.clear();
        a.s.clear();
        a.u.clear();
        a.w.clear();
        a.y.clear();
        a.x.clear();
        a.v.clear();
        a.z.clear();
        a.aa.clear();
    };
    AxisAnnotationFrameManager.a = function (a, b, c) {
        if (!b.ci) {
            return a;
        }
        var d = 0;
        if (c >= 0) {
            d = c;
        }
        else {
            var e = b.eu();
            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.an.add(q); };
                    p.disactivate = function (q) { return o.an.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.k = false;
                q.value = b.p._inner[n];
                var r = b.q._inner[n];
                if (i != null) {
                    var s = i(r);
                    q.text = s;
                }
                else {
                    r = AxisAnnotationFrameManager.a(r, o, g);
                    if (o.bh != null) {
                        q.text = o.gc(r);
                    }
                }
                q.textColor = b.o._inner[n];
                q.background = b.h._inner[n];
                q.backgroundCornerRadius = b.g._inner[n];
                q.backgroundPadding = new Thickness(1, b.k._inner[n], b.m._inner[n], b.l._inner[n], b.j._inner[n]);
                q.outline = b.i._inner[n];
                q.strokeThickness = b.n._inner[n];
                if (q.k) {
                    q.k = false;
                    c = true;
                }
            }
        };
        for (var n = 0; n < b.q.count; n++) {
            _loop_1(n);
        }
        var _loop_2 = function (t) {
            var u = b.r._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.an.add(w); };
                    v.disactivate = function (w) { return u.an.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.k = false;
                var x = b.ac._inner[t];
                w.value = b.ab._inner[t];
                if (j != null) {
                    var y = j(x);
                    w.text = y;
                }
                else {
                    x = AxisAnnotationFrameManager.a(x, u, h);
                    if (u.bh != null) {
                        w.text = u.gc(x);
                    }
                }
                w.textColor = b.aa._inner[t];
                w.background = b.t._inner[t];
                w.backgroundCornerRadius = b.s._inner[t];
                w.backgroundPadding = new Thickness(1, b.w._inner[t], b.y._inner[t], b.x._inner[t], b.v._inner[t]);
                w.outline = b.u._inner[t];
                w.strokeThickness = b.z._inner[t];
                if (w.k) {
                    w.k = false;
                    c = true;
                }
            }
        };
        for (var t = 0; t < b.ac.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.a5.c) {
                    ae.hj(true);
                    ae.a5.c = false;
                }
            }
        }
    };
    AxisAnnotationFrameManager.$t = markType(AxisAnnotationFrameManager, 'AxisAnnotationFrameManager');
    return AxisAnnotationFrameManager;
}(Base));
export { AxisAnnotationFrameManager };
