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