/*
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 { AnnotationLayer } from "./AnnotationLayer";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { Base, Type, String_$type, typeCast, enumGetBox, fromEnum, runOn, delegateCombine, delegateRemove, Date_$type, Point_$type, markType } from "igniteui-react-core/ES5/type";
import { Series } from "./Series";
import { Brush } from "igniteui-react-core/ES5/Brush";
import { Thickness } from "igniteui-react-core/ES5/Thickness";
import { CalloutCollisionMode_$type } from "./CalloutCollisionMode";
import { FontUtil } from "igniteui-react-core/ES5/FontUtil";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { CalloutLayerFrame } from "./CalloutLayerFrame";
import { HashSet$1 } from "igniteui-react-core/ES5/HashSet$1";
import { CalloutAnnotationWrapper } from "./CalloutAnnotationWrapper";
import { List$1 } from "igniteui-react-core/ES5/List$1";
import { LinkedList$1 } from "igniteui-react-core/ES5/LinkedList$1";
import { Dictionary$2 } from "igniteui-react-core/ES5/Dictionary$2";
import { LinkedListNode$1 } from "igniteui-react-core/ES5/LinkedListNode$1";
import { LabelCollisionManager } from "igniteui-react-core/ES5/LabelCollisionManager";
import { SeriesPointOfInterest } from "./SeriesPointOfInterest";
import { CalloutAnnotation } from "./CalloutAnnotation";
import { IFastItemsSource_$type } from "igniteui-react-core/ES5/IFastItemsSource";
import { CalloutSeriesSelectingEventArgs } from "./CalloutSeriesSelectingEventArgs";
import { CalloutStyleUpdatingEventArgs } from "./CalloutStyleUpdatingEventArgs";
import { QuadTreeBoundingBox } from "igniteui-react-core/ES5/QuadTreeBoundingBox";
import { LabelCollisionInfo } from "igniteui-react-core/ES5/LabelCollisionInfo";
import { ScalerParams } from "./ScalerParams";
import { Size } from "igniteui-react-core/ES5/Size";
import { CalloutContentUpdatingEventArgs } from "./CalloutContentUpdatingEventArgs";
import { CalloutLabelUpdatingEventArgs } from "./CalloutLabelUpdatingEventArgs";
import { CalloutKey } from "./CalloutKey";
import { DataContext } from "igniteui-react-core/ES5/DataContext";
import { HashPool$2 } from "igniteui-react-core/ES5/HashPool$2";
import { PropertyMetadata } from "igniteui-react-core/ES5/PropertyMetadata";
import { isNaN_ } from "igniteui-react-core/ES5/number";
import { stringIsNullOrEmpty } from "igniteui-react-core/ES5/string";
import { FastItemObjectColumn } from "igniteui-react-core/ES5/FastItemObjectColumn";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { BrushUtil } from "igniteui-react-core/ES5/BrushUtil";
import { TextBlock } from "igniteui-react-core/ES5/TextBlock";
import { DOMExecutionContext } from "igniteui-react-core/ES5/DOMExecutionContext";
import { Color } from "igniteui-react-core/ES5/Color";
import { Line } from "igniteui-react-core/ES5/Line";
import { CalloutViewHelper } from "./CalloutViewHelper";
import { Rectangle } from "igniteui-react-core/ES5/Rectangle";
import { TranslateTransform } from "igniteui-react-core/ES5/TranslateTransform";
/**
 * @hidden
 */
var CalloutLayer = /** @class */ (function (_super) {
    tslib_1.__extends(CalloutLayer, _super);
    function CalloutLayer() {
        var _this = _super.call(this) || this;
        _this.calloutStyleUpdating = null;
        _this.m6 = null;
        _this.m7 = null;
        _this.m8 = null;
        _this.m5 = null;
        _this.m4 = null;
        _this.nu = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        _this.nx = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.ny = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.m2 = null;
        _this.nv = new LinkedList$1(CalloutAnnotationWrapper.$);
        _this.ns = new Dictionary$2(CalloutAnnotationWrapper.$, LinkedListNode$1.$.specialize(CalloutAnnotationWrapper.$), 0);
        _this.ne = null;
        _this.qn = new Rect(0, 0, 0, 1, 1);
        _this.nk = false;
        _this.n8 = 0;
        _this.qm = Rect.empty;
        _this.nj = false;
        _this.calloutContentUpdating = null;
        _this.calloutLabelUpdating = null;
        _this.calloutSeriesSelecting = null;
        _this.nw = new List$1(SeriesPointOfInterest.$, 0);
        _this.nm = false;
        _this.nn = false;
        _this.n0 = 0;
        _this.nl = false;
        _this.ni = true;
        FastItemObjectColumn.k();
        _this.l1 = true;
        var a = new CalloutLayerFrame();
        var b = new CalloutLayerFrame();
        var c = new CalloutLayerFrame();
        var d = _this.ff / 1000;
        _this.lv = a;
        _this.lu = b;
        _this.lw = c;
        _this.ab = CalloutLayer.$;
        return _this;
    }
    CalloutLayer.prototype.pf = function (a, b) {
        this.ny.clear();
        this.i6(false);
    };
    CalloutLayer.prototype.hs = function (a, b, c, d) {
        _super.prototype.hs.call(this, a, b, c, d);
        var e = this.nt();
        switch (a) {
            case 3:
                this.pr(b, e);
                break;
            case 1:
                for (var f = b; f < b + c; f++) {
                    var g = new CalloutAnnotation();
                    var h = new CalloutAnnotationWrapper();
                    h.b = g;
                    h.b.series = this.m1;
                    this.ny.insert(f, h);
                    this.pr(f, e);
                }
                break;
            case 0:
                this.ny.v(b, c);
                break;
            case 2:
                for (var i = b; i < b + c; i++) {
                    this.pr(i, e);
                }
                break;
            case 4:
                this.ny.clear();
                for (var j = 0; j < this.bz.count; j++) {
                    var k = new CalloutAnnotation();
                    var l = new CalloutAnnotationWrapper();
                    l.b = k;
                    l.b.series = this.m1;
                    this.ny.add(l);
                    this.pr(j, e);
                }
                break;
        }
        this.i6(true);
    };
    CalloutLayer.prototype.c9 = function (a) {
        return false;
    };
    CalloutLayer.prototype.nt = function () {
        var a = new Dictionary$2(String_$type, Series.$, 0);
        if (this.bs != null) {
            for (var b = 0; b < this.bs.series.count; b++) {
                var c = this.bs.series._inner[b];
                if (c.name != null && !a.containsKey(c.name)) {
                    a.addItem(c.name, c);
                }
            }
        }
        return a;
    };
    CalloutLayer.prototype.pr = function (a, b) {
        var _this = this;
        if (this.nd == null || this.nb == null) {
            return;
        }
        var c = a;
        if (this.nc != null) {
            c = this.nc.item(a);
        }
        var d = this.nd.item(a);
        var e = this.nb.item(a);
        var f = this.ny._inner[a];
        f.b.xValue = c;
        f.b.yValue = d;
        f.b.text = e != null ? e.toString() : "";
        if (this.na != null) {
            f.b.key = this.na.item(a);
        }
        if (this.m9 != null) {
            f.b.content = this.m9.item(a);
        }
        else {
            f.b.content = this.bz.item(a);
        }
        if (this.calloutSeriesSelecting != null) {
            var g = ((function () {
                var $ret = new CalloutSeriesSelectingEventArgs();
                $ret.c = c;
                $ret.d = d;
                $ret.item = _this.bz.item(a);
                return $ret;
            })());
            this.calloutSeriesSelecting(this, g);
            if (g.a != null) {
                f.b.series = g.a;
            }
            else if (g.e != null) {
                if (b.containsKey(g.e)) {
                    f.b.series = b.item(g.e);
                }
            }
        }
        this.ps(f);
    };
    CalloutLayer.prototype.ps = function (a) {
        var b = new Thickness(0, 3);
        if (isNaN_(this.qp.c) || isNaN_(this.qp.e) || isNaN_(this.qp.d) || isNaN_(this.qp.b)) {
            b = new Thickness(0, 3);
        }
        else {
            b = this.qp;
        }
        var c = this.qi != null ? this.qi : this.my.ce(a.b.series);
        var d = this.ql != null ? this.ql : this.my.ch();
        var e = this.qk != null ? this.qk : this.my.cg();
        var f = this.qj != null ? this.qj : this.my.cf(a.b.series);
        var g = isNaN_(this.n6) ? 0 : this.n6;
        if (this.nq && this.calloutStyleUpdating != null) {
            var h = new CalloutStyleUpdatingEventArgs();
            h.item = a.b.content;
            h.xValue = a.b.xValue;
            h.yValue = a.b.yValue;
            h.series = a.b.series;
            h.background = c;
            h.textColor = d;
            h.outline = e;
            h.leaderBrush = f;
            h.strokeThickness = g;
            this.calloutStyleUpdating(this, h);
            c = h.background;
            d = h.textColor;
            e = h.outline;
            f = h.leaderBrush;
            g = h.strokeThickness;
        }
        a.b.backgroundPadding = b;
        a.b.background = c;
        a.b.textColor = d;
        a.b.outline = e;
        a.b.leaderBrush = f;
        a.b.strokeThickness = g;
    };
    Object.defineProperty(CalloutLayer.prototype, "nb", {
        get: function () {
            return this.m6;
        },
        set: function (a) {
            if (this.m6 != a) {
                var b = this.m6;
                this.m6 = a;
                this.raisePropertyChanged("LabelColumn", b, this.m6);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "nc", {
        get: function () {
            return this.m7;
        },
        set: function (a) {
            if (this.m7 != a) {
                var b = this.m7;
                this.m7 = a;
                this.raisePropertyChanged("XColumn", b, this.m7);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "nd", {
        get: function () {
            return this.m8;
        },
        set: function (a) {
            if (this.m8 != a) {
                var b = this.m8;
                this.m8 = a;
                this.raisePropertyChanged("YColumn", b, this.m8);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "na", {
        get: function () {
            return this.m5;
        },
        set: function (a) {
            if (this.m5 != a) {
                var b = this.m5;
                this.m5 = a;
                this.raisePropertyChanged("KeyColumn", b, this.m5);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "m9", {
        get: function () {
            return this.m4;
        },
        set: function (a) {
            if (this.m4 != a) {
                var b = this.m4;
                this.m4 = a;
                this.raisePropertyChanged("ContentColumn", b, this.m4);
            }
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.ph = function (a, b) {
        if (b.propertyName == CalloutAnnotation.$$p[13] || b.propertyName == CalloutAnnotation.$$p[14]) {
            var c = a.k;
            if (!this.nu.contains(c)) {
                this.nx.add(c);
                this.i6(false);
            }
        }
    };
    CalloutLayer.prototype.bf = function () {
        return new CalloutLayerView(this);
    };
    CalloutLayer.prototype.im = function (a) {
        _super.prototype.im.call(this, a);
        this.my = a;
    };
    Object.defineProperty(CalloutLayer.prototype, "qp", {
        get: function () {
            return new Thickness(1, this.n2, this.n4, this.n3, this.n1);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "m3", {
        get: function () {
            if (this.m2 == null) {
                this.m2 = FontUtil.toFontInfo(this.e1, this.o6);
            }
            return this.m2;
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.mc = function (a, b) {
        if (this.m1 == null || this.m1 == a) {
            if (!this.aq.c) {
                this.i6(b);
            }
        }
    };
    CalloutLayer.prototype.me = function (a, b) {
        var e_1, _a;
        _super.prototype.me.call(this, a, b);
        var c = a;
        c.p.clear();
        c.q.clear();
        c.m.clear();
        c.f.clear();
        c.h.clear();
        c.g.clear();
        c.j.clear();
        c.l.clear();
        c.k.clear();
        c.i.clear();
        c.n.clear();
        c.o.clear();
        c.t.clear();
        c.u.clear();
        c.r.clear();
        c.s.clear();
        var d = this.nz();
        var e = new List$1(CalloutAnnotationWrapper.$, 0);
        if (this.no) {
            if (this.lz(this.m1)) {
                this.po(this.m1, c, e);
            }
            else {
                try {
                    for (var _b = tslib_1.__values(fromEnum(this.bs.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var f = _c.value;
                        if (this.lz(f)) {
                            this.po(f, c, e);
                        }
                    }
                }
                catch (e_1_1) { e_1 = { error: e_1_1 }; }
                finally {
                    try {
                        if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                    }
                    finally { if (e_1) throw e_1.error; }
                }
            }
        }
        this.pn(c, d, e);
    };
    CalloutLayer.prototype.jm = function (a, b) {
        _super.prototype.jm.call(this, a, b);
        var c = b.width - this.qn.width;
        var d = b.height - this.qn.height;
        var e = 0;
        if (Math.abs(c) > Math.abs(d)) {
            e = c;
            this.n0 = c * this.lr.width;
        }
        else {
            e = d;
            this.n0 = d * this.lr.height;
        }
        if (e > 0 && this.n0 > 5) {
            this.nn = true;
        }
        if (e < 0 && this.n0 > 5) {
            this.nm = true;
        }
    };
    CalloutLayer.prototype.jl = function (a, b) {
        _super.prototype.jl.call(this, a, b);
        if (!a.equals1(b)) {
            this.nl = true;
        }
    };
    Object.defineProperty(CalloutLayer.prototype, "qo", {
        get: function () {
            return this.qm;
        },
        set: function (a) {
            this.qm = a;
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.pn = function (a, b, c) {
        if (this.bs != null) {
            this.qn = this.bs.mq;
        }
        if (this.lr.isEmpty) {
            return;
        }
        this.qo = new Rect(0, this.lr.left, this.lr.top, this.lr.width, this.lr.height);
        if (this.ne != null && this.or != null && this.or != this.ne.ak) {
            this.pj();
        }
        if (this.ne == null) {
            var d = this.nf();
            if (d != null) {
                this.ne = d;
                var e = this.ne;
                e.labelsMoved = delegateCombine(e.labelsMoved, runOn(this, this.pg));
            }
            else {
                var f = this.lj(this.bi);
                this.ne = new LabelCollisionManager(this.lr.right, this.lr.bottom, this.lr, this.my.b4(), this.n5, this.ng(), this.oc(), this.ob(), this.np);
                if (this.or != null) {
                    this.ne.ak = this.or;
                    this.ne.ai = this;
                }
                var g = this.ne;
                g.labelsMoved = delegateCombine(g.labelsMoved, runOn(this, this.pg));
            }
        }
        if (this.nm) {
            this.nm = false;
            if (this.ne.ag > 2) {
                this.nk = true;
            }
        }
        if (this.nn) {
            this.nn = false;
            if (this.n0 > 5) {
                this.nk = true;
            }
        }
        if (this.nl) {
            this.nl = false;
            this.ne.ax(this.lr.right, this.lr.bottom, this.lr);
            this.nk = true;
        }
        var h = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        var i = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        var j = new List$1(CalloutAnnotationWrapper.$, 0);
        var k = new List$1(CalloutAnnotationWrapper.$, 0);
        var l = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        for (var m = 0; m < b.count; m++) {
            l.add_1(b._inner[m]);
        }
        for (var n = 0; n < c.count; n++) {
            l.add_1(c._inner[n]);
        }
        var o = this.nv.c;
        while (o != null) {
            var p = o.a;
            if (!l.contains(o.c)) {
                k.add(o.c);
                i.add_1(o.c);
                var q = o.c.b;
                q.propertyChanged = delegateRemove(q.propertyChanged, runOn(this, this.ph));
                this.nv.h(o);
                this.ns.removeItem(o.c);
                this.ne.aw(o.c.c);
            }
            o = p;
        }
        for (var r = 0; r < b.count; r++) {
            if (!this.ns.containsKey(b._inner[r])) {
                this.nv.f(b._inner[r]);
                var s = b._inner[r].b;
                s.propertyChanged = delegateCombine(s.propertyChanged, runOn(this, this.ph));
                this.ns.addItem(b._inner[r], this.nv.d);
                j.add(b._inner[r]);
                h.add_1(b._inner[r]);
                this.nk = true;
            }
        }
        for (var t = 0; t < c.count; t++) {
            if (!this.ns.containsKey(c._inner[t])) {
                this.nv.f(c._inner[t]);
                this.ns.addItem(c._inner[t], this.nv.d);
                var u = c._inner[t].b;
                u.propertyChanged = delegateCombine(u.propertyChanged, runOn(this, this.ph));
                j.add(c._inner[t]);
                h.add_1(c._inner[t]);
                this.nk = true;
            }
        }
        if (this.nx.count > 0) {
            this.nk = true;
            this.nx.clear();
            this.nu.clear();
        }
        o = this.nv.c;
        while (o != null) {
            var v = this.nh(o.c);
            if (v == null) {
                return;
            }
            if (!Base.equalsStatic(v, o.c.c.c)) {
                var w = false;
                if (o.c.c.c == null) {
                    w = true;
                }
                var x = o.c.c;
                x.o = v.b;
                x.p = v.c;
                if (!isNaN_(x.o) && !isNaN_(x.p)) {
                    x.n = v.e;
                    x.m = v.d;
                    if (x.b == null) {
                        this.ne.p(x);
                    }
                    if (w) {
                        this.ne.al(x);
                    }
                    else {
                        this.ne.at(x);
                    }
                }
            }
            o = o.a;
        }
        var y = this.ne.ah();
        var z = this.ne.q();
        if (this.nk && (y != 0 || z)) {
            this.nk = false;
            this.n8 = 0x7FFFFFFF;
            if (this.or != null) {
                var aa = true;
                for (var ab = 0; ab < this.bs.series.count; ab++) {
                    var ac = this.bs.series._inner[ab];
                    if (ac.cj && typeCast(CalloutLayer.$, ac) !== null) {
                        var ad = ac;
                        if (ad.or == this.or) {
                            if (!ad.qo.equals1(this.ne.az)) {
                                aa = false;
                                break;
                            }
                        }
                    }
                }
                if (aa) {
                    this.ne.ay();
                }
                else {
                    this.ne.am();
                }
            }
            else {
                this.ne.ay();
            }
        }
        var ae = this.nv.c;
        while (ae != null) {
            var af = ae.c;
            a.m.add1(af);
            a.f.add(af.b.background);
            a.h.add(af.b.outline);
            a.g.add(af.b.leaderBrush);
            a.j.add(af.b.backgroundPadding.c);
            a.l.add(af.b.backgroundPadding.e);
            a.k.add(af.b.backgroundPadding.d);
            a.i.add(af.b.backgroundPadding.b);
            a.n.add(af.b.strokeThickness);
            a.o.add(af.b.textColor);
            a.p.add1(af.b.text);
            a.q.add1(af.b.content);
            var ag = af.c;
            a.t.add(af.c.o - (af.c.g - af.c.l));
            a.u.add(af.c.p - (af.c.h - af.c.k));
            a.r.add(af.c.g - af.c.l);
            a.s.add(af.c.h - af.c.k);
            ae = ae.a;
        }
    };
    CalloutLayer.prototype.pj = function () {
        if (this.ne != null) {
            var a = this.nv.c;
            while (a != null) {
                var b = a.c.c;
                if (b != null) {
                    this.ne.aw(b);
                }
                a = a.a;
            }
            var c = this.ne;
            c.labelsMoved = delegateRemove(c.labelsMoved, runOn(this, this.pg));
            this.ne = null;
        }
        this.pi();
    };
    CalloutLayer.prototype.nf = function () {
        if (this.bs == null) {
            return null;
        }
        for (var a = 0; a < this.bs.series.count; a++) {
            var b = this.bs.series._inner[a];
            if (b.cj && typeCast(CalloutLayer.$, b) !== null) {
                var c = b;
                if (c != this) {
                    if (c.or != null && c.or == this.or) {
                        if (c.ne != null) {
                            return c.ne;
                        }
                    }
                }
            }
        }
        return null;
    };
    CalloutLayer.prototype.ob = function () {
        return 20000;
    };
    CalloutLayer.prototype.oc = function () {
        return 300;
    };
    CalloutLayer.prototype.ng = function () {
        switch (this.mv) {
            case 0: return 2;
            case 2: return 1;
            case 3: return 2;
            case 1: return 0;
        }
        return 2;
    };
    CalloutLayer.prototype.pg = function (a) {
        var b = this.ne.ah();
        if (b < this.n8) {
            this.n8 = b;
            this.i6(false);
        }
    };
    CalloutLayer.prototype.nh = function (a) {
        var b = this.m1;
        if (a.b.series != null) {
            b = a.b.series;
        }
        if (b == null) {
            for (var c = 0; c < this.bs.series.count; c++) {
                var d = this.bs.series._inner[c];
                if (!d.cj) {
                    b = d;
                    break;
                }
            }
        }
        if (b == null) {
            return null;
        }
        var e = b.ag();
        var f = b.ee();
        var g = null;
        var h = null;
        for (var i = 0; i < e.length; i++) {
            if (e[i].ce) {
                h = e[i];
            }
            else {
                g = e[i];
            }
        }
        if (g == null || h == null) {
            return null;
        }
        if (!g.cd() || !h.cd()) {
            return null;
        }
        var j = 0;
        if (g.b2 && g.categoryMode != 0) {
            if (b.cr) {
                j = b.getOffsetValue();
            }
            else if (b.cl) {
                j = b.getOffsetValue();
            }
        }
        var k = new ScalerParams(0, this.bs.mq, g.iu, g.b8, g.ip());
        k.b = f;
        var l = new ScalerParams(0, this.bs.mq, h.iu, h.b8, h.ip());
        l.b = f;
        var m = g.dt(this.n7(a.b.xValue), k) + j;
        var n = h.dt(this.n7(a.b.yValue), l);
        var o = new QuadTreeBoundingBox();
        o.b = m;
        o.c = n;
        o.e = 3;
        o.d = 3;
        o.g = a.b;
        return o;
    };
    CalloutLayer.prototype.n7 = function (a) {
        if (typeCast(Date_$type, a) !== null) {
            return a.getTime();
        }
        if (a == null) {
            return 0;
        }
        return a;
    };
    CalloutLayer.prototype.nz = function () {
        var a = new List$1(CalloutAnnotationWrapper.$, 0);
        for (var b = 0; b < this.ny.count; b++) {
            if (stringIsNullOrEmpty(this.ny._inner[b].b.text)) {
                continue;
            }
            if (this.ny._inner[b].c == null) {
                var c = new LabelCollisionInfo();
                this.ny._inner[b].c = c;
                var d = this.my.cj(this.od(this.ny._inner[b]), this.ny._inner[b].b.backgroundPadding);
                c.k = d.height / 2;
                c.l = d.width / 2;
            }
            var e = this.nh(this.ny._inner[b]);
            if (e == null || e.b < this.lr.left || e.b > this.lr.right || e.c < this.lr.top || e.c > this.lr.bottom) {
                continue;
            }
            a.add(this.ny._inner[b]);
        }
        return a;
    };
    CalloutLayer.prototype.od = function (a) {
        return a.b.text;
    };
    CalloutLayer.prototype.lz = function (a) {
        if (!_super.prototype.lz.call(this, a)) {
            return false;
        }
        return true;
    };
    CalloutLayer.prototype.ig = function () {
        _super.prototype.ig.call(this);
        if (!this.aq.c && !this.ca()) {
            return;
        }
        if (this.ni) {
            this.ni = false;
            this.pl();
        }
        if (this.ca()) {
            this.pq(this.lw, false);
        }
        else {
            this.pq(this.lu, false);
        }
    };
    CalloutLayer.prototype.pm = function () {
        if (!this.nj) {
            this.nj = true;
            this.i6(true);
        }
    };
    CalloutLayer.prototype.po = function (a, b, c) {
        if (a.ch(this.nw, this.nr, this.n9)) {
            var d = this.nw;
            var _loop_1 = function (e) {
                var f = d._inner[e];
                var g = f.a.item != null ? f.a.item : f.a;
                var h = a;
                var i = new CalloutKey(g, h);
                var j = new CalloutAnnotationWrapper();
                var k = new CalloutAnnotation();
                j.b = k;
                k.key = i;
                var l = false;
                var m = false;
                if (this_1.nj) {
                    this_1.nj = false;
                    m = true;
                }
                if (this_1.ns.containsKey(j)) {
                    j = this_1.ns.item(j).c;
                    k = j.b;
                }
                else {
                    if (!m) {
                        l = true;
                    }
                }
                var n = k.xValue;
                var o = k.yValue;
                if (this_1.n7(n) != this_1.n7(f.b)) {
                    k.xValue = f.b;
                }
                if (this_1.n7(o) != this_1.n7(f.c)) {
                    k.yValue = f.c;
                }
                k.series = a;
                if (l && this_1.calloutLabelUpdating != null) {
                    var p = ((function () {
                        var $ret = new CalloutLabelUpdatingEventArgs();
                        $ret.c = k.xValue;
                        $ret.d = k.yValue;
                        $ret.item = g;
                        return $ret;
                    })());
                    this_1.calloutLabelUpdating(this_1, p);
                    if (p.b != null && !Base.equalsStatic(p.b, j.b.text)) {
                        var q = p.b;
                        j.b.text = q != null ? q.toString() : "";
                    }
                }
                else {
                    if (f.d != null) {
                        k.text = f.d;
                    }
                }
                if (k.text == null) {
                    return "continue";
                }
                if (l) {
                    if (this_1.calloutContentUpdating != null) {
                        var r = ((function () {
                            var $ret = new CalloutContentUpdatingEventArgs();
                            $ret.c = k.xValue;
                            $ret.d = k.yValue;
                            $ret.item = g;
                            $ret.a = g;
                            return $ret;
                        })());
                        this_1.calloutContentUpdating(this_1, r);
                        if (r.a != null && r.a != j.b.content) {
                            j.b.content = r.a;
                        }
                    }
                    else {
                        if (g != null && g != j.b.content) {
                            j.b.content = g;
                        }
                    }
                }
                if (l) {
                    this_1.ps(j);
                }
                if (j.c == null) {
                    var s = new LabelCollisionInfo();
                    j.c = s;
                    var t = this_1.my.cj(this_1.od(j), j.b.backgroundPadding);
                    s.k = t.height / 2;
                    s.l = t.width / 2;
                }
                var u = this_1.nh(j);
                if (u == null || u.b < this_1.lr.left || u.b > this_1.lr.right || u.c < this_1.lr.top || u.c > this_1.lr.bottom) {
                    return "continue";
                }
                c.add(j);
            };
            var this_1 = this;
            for (var e = 0; e < this.nw.count; e++) {
                _loop_1(e);
            }
        }
    };
    CalloutLayer.prototype.bd = function () {
        return 1;
    };
    CalloutLayer.prototype.ar = function (a, b) {
        var c = this.ne.d(a, b);
        if (c == null) {
            return null;
        }
        return c.u;
    };
    CalloutLayer.prototype.dg = function (a, b) {
        if (this.ne == null) {
            return false;
        }
        return this.ne.d(a, b) != null;
    };
    CalloutLayer.prototype.pq = function (a, b) {
        var e_2, _a;
        var c = 0;
        var d = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        for (c = 0; c < a.p.count; c++) {
            var e = a.m._inner[c];
            if (isNaN_(a.t._inner[c]) || isNaN_(a.u._inner[c])) {
                continue;
            }
            var f = this.my.b6.item(e);
            d.add_1(e);
            if (f.f != a.p._inner[c]) {
                f.f = a.p._inner[c];
                var g = f.s();
            }
            f.c = a.n._inner[c];
            f.k = a.f._inner[c];
            f.n = a.o._inner[c];
            f.m = f.c > 0 ? a.h._inner[c] : this.bi.bn();
            f.l = a.g._inner[c];
            f.v = new Thickness(1, a.j._inner[c], a.l._inner[c], a.k._inner[c], a.i._inner[c]);
            this.my.cc(f, Math.min(a.r._inner[c], a.r._inner[c] + a.t._inner[c]), Math.min(a.s._inner[c], a.s._inner[c] + a.u._inner[c]));
            this.my.cd(f, e, a.q._inner[c]);
            f.p = { $type: Point_$type, x: a.t._inner[c], y: a.u._inner[c] };
        }
        var h = new List$1(CalloutAnnotationWrapper.$, 0);
        try {
            for (var _b = tslib_1.__values(fromEnum(this.my.b6.c)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var i = _c.value;
                if (!d.contains(i)) {
                    h.add(i);
                }
            }
        }
        catch (e_2_1) { e_2 = { error: e_2_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_2) throw e_2.error; }
        }
        for (var j = 0; j < h.count; j++) {
            this.my.b6.g(h._inner[j]);
        }
    };
    CalloutLayer.prototype.mh = function (a, b) {
        _super.prototype.mh.call(this, a, b);
        if (this.ca()) {
            this.pq(this.lw, true);
        }
        else {
            this.pq(this.lu, false);
        }
    };
    CalloutLayer.prototype.c7 = function () {
        return true;
    };
    CalloutLayer.prototype.is = function (a, b, c, d) {
        _super.prototype.is.call(this, a, b, c, d);
        switch (b) {
            case CalloutLayer.$$p[21]:
                this.m2 = null;
                this.i6(true);
                break;
            case CalloutLayer.$$p[20]:
                this.i6(true);
                break;
            case CalloutLayer.$$p[13]:
                this.i6(true);
                break;
            case "SeriesViewer":
                if (c != null) {
                    var e = c;
                    e.seriesAnimating = delegateRemove(e.seriesAnimating, runOn(this, this.pp));
                }
                if (d != null) {
                    var f = d;
                    f.seriesAnimating = delegateCombine(f.seriesAnimating, runOn(this, this.pp));
                }
                if (d == null) {
                    this.pj();
                }
                break;
            case CalloutLayer.$$p[15]:
            case CalloutLayer.$$p[16]:
            case CalloutLayer.$$p[1]:
            case CalloutLayer.$$p[5]:
            case CalloutLayer.$$p[4]:
            case CalloutLayer.$$p[7]:
            case CalloutLayer.$$p[9]:
            case CalloutLayer.$$p[8]:
            case CalloutLayer.$$p[6]:
            case CalloutLayer.$$p[11]:
            case CalloutLayer.$$p[12]:
                this.pk();
                break;
            case CalloutLayer.$$p[19]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nb);
                    this.nb = this.by(this.o3);
                }
                break;
            case "LabelColumn":
                this.pk();
                break;
            case CalloutLayer.$$p[14]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.m9);
                    this.m9 = this.by(this.ou);
                }
                break;
            case "ContentColumn":
                this.pk();
                break;
            case CalloutLayer.$$p[23]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nc);
                    this.nc = stringIsNullOrEmpty(this.pa) == false ? this.by(this.pa) : null;
                }
                break;
            case "XColumn":
                this.pk();
                break;
            case CalloutLayer.$$p[24]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nd);
                    this.nd = this.by(this.pd);
                }
                break;
            case "YColumn":
                this.pk();
                break;
            case CalloutLayer.$$p[18]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.na);
                    this.na = this.by(this.o0);
                }
                break;
            case "KeyColumn":
                this.pk();
                break;
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.nb);
                    c.deregisterColumn(this.m9);
                    c.deregisterColumn(this.nc);
                    c.deregisterColumn(this.nd);
                    c.deregisterColumn(this.na);
                    this.nb = null;
                    this.m9 = null;
                    this.nc = null;
                    this.nd = null;
                    this.na = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.nb = this.by(this.o3);
                    this.m9 = this.by(this.ou);
                    if (stringIsNullOrEmpty(this.pa) == false) {
                        this.nc = this.by(this.pa);
                    }
                    this.nd = this.by(this.pd);
                    this.na = this.by(this.o0);
                }
                this.pk();
                break;
        }
    };
    CalloutLayer.prototype.pp = function (a) {
        if (a.cj) {
            return;
        }
        if ((a == this.m1 || this.m1 == null) && this.no) {
            this.i6(false);
        }
    };
    CalloutLayer.prototype.pk = function () {
        if (this.ni == false) {
            this.ni = true;
            this.i6(false);
        }
    };
    CalloutLayer.prototype.pi = function () {
        this.my.b6.clear();
        this.nv.g();
        this.ns.clear();
    };
    CalloutLayer.prototype.pl = function () {
        if (this.nd == null || this.nb == null) {
            var a = this.nv.c;
            while (a != null) {
                this.ps(a.c);
                a = a.a;
            }
            return;
        }
        var b = this.nt();
        for (var c = 0; c < this.nd.count; c++) {
            var d = void 0;
            if (this.ny.count <= c) {
                var e = new CalloutAnnotation();
                d = new CalloutAnnotationWrapper();
                d.b = e;
                d.b.series = this.m1;
                this.ny.add(d);
            }
            else {
                d = this.ny._inner[c];
            }
            this.pr(c, b);
        }
    };
    CalloutLayer.$t = markType(CalloutLayer, 'CalloutLayer', AnnotationLayer.$);
    return CalloutLayer;
}(AnnotationLayer));
export { CalloutLayer };
Type.dep(DependencyProperty, PropertyMetadata, CalloutLayer, 'raisePropertyChanged', ['AutoCalloutLabelPrecision:n9:pt', [1, 5], 'CalloutBackground:qi:pu', [Brush.$, null], 'CalloutCollisionMode:mv:pv', [CalloutCollisionMode_$type, enumGetBox(CalloutCollisionMode_$type, 3)], 'CalloutInterpolatedValuePrecision:oa:pw', [1, -1], 'CalloutLeaderBrush:qj:px', [Brush.$, null], 'CalloutOutline:qk:py', [Brush.$, null], 'CalloutPaddingBottom:n1:pz', [1, NaN], 'CalloutPaddingLeft:n2:p0', [1, NaN], 'CalloutPaddingRight:n3:p1', [1, NaN], 'CalloutPaddingTop:n4:p2', [1, NaN], 'CalloutPositionPadding:n5:p3', [1, 10], 'CalloutStrokeThickness:n6:p4', [1, NaN], 'CalloutTextColor:ql:p5', [Brush.$, null], 'CollisionChannel:or:p6', [2, null], 'ContentMemberPath:ou:p7', [2, null], 'IsAutoCalloutBehaviorEnabled:no:p8', [0, false], 'IsCalloutOffsettingEnabled:np:p9', [0, true], 'IsCustomCalloutStyleEnabled:nq:qa', [0, false], 'KeyMemberPath:o0:qb', [2, null], 'LabelMemberPath:o3:qc', [2, null], 'TargetSeries:m1:qd', [Series.$, null], 'TextStyle:o6:qe', [2, null], 'UseValueForAutoCalloutLabels:nr:qf', [0, true], 'XMemberPath:pa:qg', [2, null], 'YMemberPath:pd:qh', [2, null]]);
/**
 * @hidden
 */
var CalloutLayerView = /** @class */ (function (_super) {
    tslib_1.__extends(CalloutLayerView, _super);
    function CalloutLayerView(a) {
        var _this = _super.call(this, a) || this;
        _this.b1 = null;
        _this.b7 = null;
        _this.b6 = null;
        _this.b8 = NaN;
        _this.b2 = null;
        _this.b1 = a;
        _this.b7 = new List$1(CalloutView.$, 0);
        return _this;
    }
    CalloutLayerView.prototype.ap = function () {
        var _this = this;
        _super.prototype.ap.call(this);
        this.b6 = ((function () {
            var $ret = new HashPool$2(CalloutAnnotationWrapper.$, CalloutView.$);
            $ret.create = runOn(_this, _this.b3);
            $ret.activate = runOn(_this, _this.b9);
            $ret.disactivate = runOn(_this, _this.cb);
            $ret.destroy = runOn(_this, _this.ca);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.b3 = function () {
        var a = new CalloutView(this);
        this.b7.add(a);
        return a;
    };
    CalloutLayerView.prototype.b9 = function (a) {
        a.w = 0;
    };
    CalloutLayerView.prototype.cb = function (a) {
        a.w = 1;
    };
    CalloutLayerView.prototype.ca = function (a) {
        this.b7.remove(a);
    };
    CalloutLayerView.prototype.ci = function (a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.h(a, 0.1);
    };
    CalloutLayerView.prototype.a3 = function (a, b) {
        _super.prototype.a3.call(this, a, b);
        a.ac(this.b5());
        if (a.d && !b) {
            for (var c = 0; c < this.b7.count; c++) {
                var d = this.b7._inner[c];
                if (d.w == 0) {
                    d.h(a);
                }
            }
        }
    };
    CalloutLayerView.prototype.b5 = function () {
        if (this.b1.m3 != null) {
            return this.b1.m3;
        }
        return this.e.bs.getFontInfo();
    };
    CalloutLayerView.prototype.ai = function (a) {
        _super.prototype.ai.call(this, a);
        for (var b = 0; b < this.b7.count; b++) {
            var c = this.b7._inner[b];
            if (c.w != 0) {
                continue;
            }
            c.g(this.b1, this.b5(), a);
        }
    };
    CalloutLayerView.prototype.ck = function (a) {
        if (isNaN_(this.b8)) {
            this.b8 = this.e.bs.bn.a7;
        }
        return new Size(1, this.h.f(a.ak), this.b8);
    };
    CalloutLayerView.prototype.cj = function (a, b) {
        if (this.b2 == null) {
            this.b2 = new CalloutView(this);
        }
        this.b2.f = a;
        this.b2.v = b;
        var c = this.b2.s();
        this.b2.f = null;
        return c;
    };
    CalloutLayerView.prototype.b4 = function () {
        return new DOMExecutionContext(this.e.bs.bn.i.af);
    };
    CalloutLayerView.prototype.cc = function (a, b, c) {
        a.d = b;
        a.e = c;
    };
    CalloutLayerView.prototype.cd = function (a, b, c) {
        a.i(this.e, b, c);
    };
    CalloutLayerView.prototype.ce = function (a) {
        if (a != null) {
            return this.ci(a.kw);
        }
        return this.e.kw;
    };
    CalloutLayerView.prototype.ch = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.cg = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.cf = function (a) {
        if (a != null) {
            return this.ci(a.kw);
        }
        return this.e.kw;
    };
    CalloutLayerView.$t = markType(CalloutLayerView, 'CalloutLayerView', AnnotationLayerView.$);
    return CalloutLayerView;
}(AnnotationLayerView));
export { CalloutLayerView };
/**
 * @hidden
 */
var CalloutView = /** @class */ (function (_super) {
    tslib_1.__extends(CalloutView, _super);
    function CalloutView(a) {
        var _this = _super.call(this) || this;
        _this.a = null;
        _this.w = 0;
        _this.j = null;
        _this.r = null;
        _this.o = { $type: Point_$type, x: 0, y: 0 };
        _this.q = null;
        _this.u = new Thickness(0, 0);
        _this.t = null;
        _this.d = 0;
        _this.e = 0;
        _this.b = null;
        _this.q = new Line();
        _this.q.ab = false;
        _this.q._stroke = ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 0, 0, 0);
            return $ret;
        })());
        _this.q.ac = 2;
        _this.j = new TextBlock();
        _this.r = new Rectangle();
        _this.r.ac = 0;
        _this.a = a;
        _this.w = 0;
        return _this;
    }
    CalloutView.prototype.h = function (a) {
        a.z();
        a.af(this.d, this.e);
        var b = new TranslateTransform();
        b.j = this.t.c;
        b.k = this.t.e;
        this.r.j = b;
        a.r(this.q);
        a.z();
        this.r.width = this.j.m + this.u.c + this.u.d;
        this.r.height = this.j.l + this.u.e + this.u.b;
        a.j(this.r.j);
        a.v(this.r);
        this.j.o = this.u.e;
        this.j.n = this.u.c;
        a.w(this.j);
        a.y();
        a.y();
    };
    Object.defineProperty(CalloutView.prototype, "p", {
        get: function () {
            return this.o;
        },
        set: function (a) {
            if (this.o.x != a.x || this.o.y != a.y) {
                var b = this.s();
                var c = b.height;
                var d = b.width;
                this.o = a;
                var e = CalloutViewHelper.b(this.p, d, c, this.q);
                this.t = e;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "n", {
        get: function () {
            return this.j.am;
        },
        set: function (a) {
            this.j.am = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "m", {
        get: function () {
            return this.r._stroke;
        },
        set: function (a) {
            this.r._stroke = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "l", {
        get: function () {
            return this.q._stroke;
        },
        set: function (a) {
            this.q._stroke = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "k", {
        get: function () {
            return this.r._fill;
        },
        set: function (a) {
            this.r._fill = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "c", {
        get: function () {
            return this.r.ac;
        },
        set: function (a) {
            this.r.ac = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "v", {
        get: function () {
            return this.u;
        },
        set: function (a) {
            this.u = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutView.prototype, "f", {
        get: function () {
            return this.j.ak;
        },
        set: function (a) {
            if (a == null) {
                this.j.ak = "";
            }
            else {
                this.j.ak = a.toString();
            }
            var b = this.s();
            var c = b.height;
            var d = b.width;
            var e = CalloutViewHelper.b(this.p, d, c, this.q);
            this.t = e;
        },
        enumerable: true,
        configurable: true
    });
    CalloutView.prototype.s = function () {
        var a = this.a.ck(this.j);
        this.j.m = a.width;
        this.j.l = a.height;
        return new Size(1, a.width + this.u.c + this.u.d, a.height + this.u.e + this.u.b);
    };
    CalloutView.prototype.i = function (a, b, c) {
        if (this.b == null) {
            this.b = new DataContext();
        }
        this.b.series = a;
        this.b.item = c;
        if (b.c != null) {
            b.c.u = this.b;
        }
    };
    CalloutView.prototype.g = function (a, b, c) {
        a.a2.exportCalloutData(this.d, this.e, this.t.c, this.t.e, c, this.r, this.j, b, this.q, "callout", ["Main", "Callout"]);
    };
    CalloutView.$t = markType(CalloutView, 'CalloutView');
    return CalloutView;
}(Base));
export { CalloutView };
