/*
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";
import { Base, String_$type, typeCast, enumGetBox, fromEnum, runOn, delegateCombine, delegateRemove, Date_$type, Point_$type, markType, markDep } from "igniteui-react-core";
import { Series } from "./Series";
import { Brush } from "igniteui-react-core";
import { Thickness } from "igniteui-react-core";
import { CalloutCollisionMode_$type } from "./CalloutCollisionMode";
import { FontUtil } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { CalloutLayerFrame } from "./CalloutLayerFrame";
import { HashSet$1 } from "igniteui-react-core";
import { CalloutAnnotationWrapper } from "./CalloutAnnotationWrapper";
import { List$1 } from "igniteui-react-core";
import { LinkedList$1 } from "igniteui-react-core";
import { Dictionary$2 } from "igniteui-react-core";
import { LinkedListNode$1 } from "igniteui-react-core";
import { LabelCollisionManager } from "igniteui-react-core";
import { SeriesPointOfInterest } from "./SeriesPointOfInterest";
import { CalloutAnnotation } from "./CalloutAnnotation";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { CalloutLabelUpdatingEventArgs } from "./CalloutLabelUpdatingEventArgs";
import { CalloutSeriesSelectingEventArgs } from "./CalloutSeriesSelectingEventArgs";
import { CalloutStyleUpdatingEventArgs } from "./CalloutStyleUpdatingEventArgs";
import { QuadTreeBoundingBox } from "igniteui-react-core";
import { LabelCollisionInfo } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { Size } from "igniteui-react-core";
import { CalloutContentUpdatingEventArgs } from "./CalloutContentUpdatingEventArgs";
import { CalloutKey } from "./CalloutKey";
import { DataContext } from "igniteui-react-core";
import { HashPool$2 } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { isNaN_ } from "igniteui-react-core";
import { stringIsNullOrEmpty } from "igniteui-react-core";
import { FastItemObjectColumn } from "igniteui-react-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { BrushUtil } from "igniteui-react-core";
import { TextBlock } from "igniteui-react-core";
import { DOMExecutionContext } from "igniteui-react-core";
import { Color } from "igniteui-react-core";
import { Line } from "igniteui-react-core";
import { CalloutViewHelper } from "./CalloutViewHelper";
import { Rectangle } from "igniteui-react-core";
import { TranslateTransform } from "igniteui-react-core";
/**
 * @hidden
 */
var CalloutLayer = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CalloutLayer, _super);
    function CalloutLayer() {
        var _this = _super.call(this) || this;
        _this.calloutStyleUpdating = null;
        _this.np = null;
        _this.nq = null;
        _this.nr = null;
        _this.no = null;
        _this.nn = null;
        _this.oe = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        _this.oh = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.oi = new List$1(CalloutAnnotationWrapper.$, 0);
        _this.nl = null;
        _this.of = new LinkedList$1(CalloutAnnotationWrapper.$);
        _this.oc = new Dictionary$2(CalloutAnnotationWrapper.$, LinkedListNode$1.$.specialize(CalloutAnnotationWrapper.$), 0);
        _this.nx = null;
        _this.q7 = new Rect(0, 0, 0, 1, 1);
        _this.n4 = false;
        _this.os = 0;
        _this.q6 = Rect.empty;
        _this.n2 = false;
        _this.n3 = false;
        _this.calloutContentUpdating = null;
        _this.calloutLabelUpdating = null;
        _this.calloutSeriesSelecting = null;
        _this.og = new List$1(SeriesPointOfInterest.$, 0);
        _this.n6 = false;
        _this.n7 = false;
        _this.ok = 0;
        _this.n5 = false;
        _this.n1 = true;
        FastItemObjectColumn.m();
        _this.mk = true;
        var a = new CalloutLayerFrame();
        var b = new CalloutLayerFrame();
        var c = new CalloutLayerFrame();
        var d = _this.fi / 1000;
        _this.mc = a;
        _this.mb = b;
        _this.md = c;
        _this.ab = CalloutLayer.$;
        return _this;
    }
    CalloutLayer.prototype.pz = function (a, b) {
        this.oi.clear();
        this.jl(false);
    };
    CalloutLayer.prototype.h6 = function (a, b, c, d) {
        _super.prototype.h6.call(this, a, b, c, d);
        var e = this.od();
        switch (a) {
            case 3:
                this.qb(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.nk;
                    this.oi.insert(f, h);
                    this.qb(f, e);
                }
                break;
            case 0:
                this.oi.v(b, c);
                break;
            case 2:
                for (var i = b; i < b + c; i++) {
                    this.qb(i, e);
                }
                break;
            case 4:
                this.oi.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.nk;
                    this.oi.add(l);
                    this.qb(j, e);
                }
                break;
        }
        this.jl(true);
    };
    CalloutLayer.prototype.da = function (a) {
        return false;
    };
    CalloutLayer.prototype.od = 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.qb = function (a, b) {
        var _this = this;
        if (this.nw == null || this.nu == null) {
            return;
        }
        var c = a;
        if (this.nv != null) {
            c = this.nv.item(a);
        }
        var d = this.nw.item(a);
        var e = this.nu.item(a);
        var f = this.oi._inner[a];
        if (this.nt != null) {
            if (f.b.aa != this.nt.item(a)) {
                f.b.key = this.nt.item(a);
            }
        }
        if (this.oc.containsKey(f)) {
            f.b = this.oc.item(f).c.b;
        }
        f.b.xValue = c;
        f.b.yValue = d;
        if (this.calloutLabelUpdating != null) {
            var g = ((function () {
                var $ret = new CalloutLabelUpdatingEventArgs();
                $ret.c = c;
                $ret.d = d;
                $ret.item = _this.bz.item(a);
                return $ret;
            })());
            this.calloutLabelUpdating(this, g);
            if (g.b != null && !Base.equalsStatic(g.b, f.b.am)) {
                var h = g.b;
                f.b.text = h != null ? h.toString() : "";
            }
        }
        else {
            f.b.text = e != null ? e.toString() : "";
        }
        if (this.ns != null) {
            f.b.content = this.ns.item(a);
        }
        else {
            f.b.content = this.bz.item(a);
        }
        if (this.calloutSeriesSelecting != null) {
            var i = ((function () {
                var $ret = new CalloutSeriesSelectingEventArgs();
                $ret.c = c;
                $ret.d = d;
                $ret.item = _this.bz.item(a);
                return $ret;
            })());
            this.calloutSeriesSelecting(this, i);
            if (i.a != null) {
                f.b.series = i.a;
            }
            else if (i.e != null) {
                if (b.containsKey(i.e)) {
                    f.b.series = b.item(i.e);
                }
            }
        }
        this.qc(f);
    };
    CalloutLayer.prototype.qc = function (a) {
        var b = new Thickness(0, 3);
        if (isNaN_(this.q9.c) || isNaN_(this.q9.e) || isNaN_(this.q9.d) || isNaN_(this.q9.b)) {
            b = new Thickness(0, 3);
        }
        else {
            b = this.q9;
        }
        var c = this.q2 != null ? this.q2 : this.nh.cg(a.b.l);
        var d = this.q5 != null ? this.q5 : this.nh.cj();
        var e = this.q4 != null ? this.q4 : this.nh.ci();
        var f = this.q3 != null ? this.q3 : this.nh.ch(a.b.l);
        var g = isNaN_(this.oq) ? 0 : this.oq;
        if (this.oa && this.calloutStyleUpdating != null) {
            var h = new CalloutStyleUpdatingEventArgs();
            h.item = a.b.z;
            h.xValue = a.b.ab;
            h.yValue = a.b.ac;
            h.series = a.b.l;
            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;
    };
    CalloutLayer.prototype.fs = function (a, b) {
        var c = this.g2(b);
        if (c == CalloutLayer.$$p[19]) {
            return this.ft(a, b, this.pn);
        }
        if (c == CalloutLayer.$$p[23]) {
            return this.ft(a, b, this.pu);
        }
        if (c == CalloutLayer.$$p[24]) {
            return this.ft(a, b, this.px);
        }
        if (c == CalloutLayer.$$p[18]) {
            return this.ft(a, b, this.pk);
        }
        if (c == CalloutLayer.$$p[14]) {
            return this.ft(a, b, this.pe);
        }
        return _super.prototype.fs.call(this, a, b);
    };
    Object.defineProperty(CalloutLayer.prototype, "nu", {
        get: function () {
            return this.np;
        },
        set: function (a) {
            if (this.np != a) {
                var b = this.np;
                this.np = a;
                this.raisePropertyChanged("LabelColumn", b, this.np);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "nv", {
        get: function () {
            return this.nq;
        },
        set: function (a) {
            if (this.nq != a) {
                var b = this.nq;
                this.nq = a;
                this.raisePropertyChanged("XColumn", b, this.nq);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "nw", {
        get: function () {
            return this.nr;
        },
        set: function (a) {
            if (this.nr != a) {
                var b = this.nr;
                this.nr = a;
                this.raisePropertyChanged("YColumn", b, this.nr);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "nt", {
        get: function () {
            return this.no;
        },
        set: function (a) {
            if (this.no != a) {
                var b = this.no;
                this.no = a;
                this.raisePropertyChanged("KeyColumn", b, this.no);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "ns", {
        get: function () {
            return this.nn;
        },
        set: function (a) {
            if (this.nn != a) {
                var b = this.nn;
                this.nn = a;
                this.raisePropertyChanged("ContentColumn", b, this.nn);
            }
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.p1 = function (a, b) {
        if (b.propertyName == CalloutAnnotation.$$p[13] || b.propertyName == CalloutAnnotation.$$p[14]) {
            var c = a.k;
            if (!this.oe.contains(c)) {
                this.oe.add_1(c);
                this.oh.add(c);
                this.jl(false);
            }
        }
    };
    CalloutLayer.prototype.bf = function () {
        return new CalloutLayerView(this);
    };
    CalloutLayer.prototype.i2 = function (a) {
        _super.prototype.i2.call(this, a);
        this.nh = a;
    };
    Object.defineProperty(CalloutLayer.prototype, "q9", {
        get: function () {
            return new Thickness(1, this.om, this.oo, this.on, this.ol);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CalloutLayer.prototype, "nm", {
        get: function () {
            if (this.nl == null) {
                this.nl = FontUtil.toFontInfo(this.e4, this.pq);
            }
            return this.nl;
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.mv = function (a, b) {
        if (this.nk == null || this.nk == a) {
            if (!this.aq.c) {
                this.jl(b);
            }
        }
    };
    CalloutLayer.prototype.mx = function (a, b) {
        var e_1, _a;
        _super.prototype.mx.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.oj();
        var e = new List$1(CalloutAnnotationWrapper.$, 0);
        if (this.n8) {
            if (this.mi(this.nk)) {
                this.p8(this.nk, 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.mi(f)) {
                            this.p8(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.p7(c, d, e);
    };
    CalloutLayer.prototype.j1 = function (a, b) {
        _super.prototype.j1.call(this, a, b);
        var c = b.width - this.q7.width;
        var d = b.height - this.q7.height;
        var e = 0;
        if (Math.abs(c) > Math.abs(d)) {
            e = c;
            this.ok = c * this.l8.width;
        }
        else {
            e = d;
            this.ok = d * this.l8.height;
        }
        if (e > 0 && this.ok > 5) {
            this.n7 = true;
        }
        if (e < 0 && this.ok > 5) {
            this.n6 = true;
        }
    };
    CalloutLayer.prototype.j0 = function (a, b) {
        _super.prototype.j0.call(this, a, b);
        if (!a.equals1(b)) {
            this.n5 = true;
        }
    };
    Object.defineProperty(CalloutLayer.prototype, "q8", {
        get: function () {
            return this.q6;
        },
        set: function (a) {
            this.q6 = a;
        },
        enumerable: true,
        configurable: true
    });
    CalloutLayer.prototype.p7 = function (a, b, c) {
        var e_2, _a;
        if (this.bs != null) {
            this.q7 = this.bs.n2;
        }
        if (this.l8.isEmpty) {
            return;
        }
        this.q8 = new Rect(0, this.l8.left, this.l8.top, this.l8.width, this.l8.height);
        if (this.nx != null && this.pb != null && this.pb != this.nx.ak) {
            this.p3();
        }
        if (this.nx == null) {
            var d = this.ny();
            if (d != null) {
                this.nx = d;
                var e = this.nx;
                e.labelsMoved = delegateCombine(e.labelsMoved, runOn(this, this.p0));
            }
            else {
                var f = this.l0(this.bi);
                var g = 0;
                if (this.nk != null) {
                    if (this.nk.isVertical) {
                        g = 2;
                    }
                }
                else {
                    var h = false;
                    if (this.bs != null && this.bs.series.count > 0) {
                        h = true;
                        try {
                            for (var _b = tslib_1.__values(fromEnum(this.bs.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                                var i = _c.value;
                                if (!i.cj) {
                                    if (!i.isVertical) {
                                        h = false;
                                    }
                                }
                            }
                        }
                        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;
                            }
                        }
                    }
                    if (h) {
                        g = 2;
                    }
                }
                this.nx = new LabelCollisionManager(this.l8.right, this.l8.bottom, this.l8, this.nh.b4(), this.op, this.nz(), g, this.ow(), this.ov(), this.n9);
                if (this.pb != null) {
                    this.nx.ak = this.pb;
                    this.nx.ai = this;
                }
                var j = this.nx;
                j.labelsMoved = delegateCombine(j.labelsMoved, runOn(this, this.p0));
            }
        }
        if (this.n6) {
            this.n6 = false;
            if (this.nx.ag > 2) {
                this.n4 = true;
            }
        }
        if (this.n7) {
            this.n7 = false;
            if (this.ok > 5) {
                this.n4 = true;
            }
        }
        if (this.n5) {
            this.n5 = false;
            this.nx.ay(this.l8.right, this.l8.bottom, this.l8);
            this.n4 = true;
        }
        var k = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        var l = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        var m = new List$1(CalloutAnnotationWrapper.$, 0);
        var n = new List$1(CalloutAnnotationWrapper.$, 0);
        var o = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        for (var p = 0; p < b.count; p++) {
            o.add_1(b._inner[p]);
        }
        for (var q = 0; q < c.count; q++) {
            o.add_1(c._inner[q]);
        }
        var r = this.of.c;
        while (r != null) {
            var s = r.a;
            if (!o.contains(r.c)) {
                n.add(r.c);
                l.add_1(r.c);
                var t = r.c.b;
                t.propertyChanged = delegateRemove(t.propertyChanged, runOn(this, this.p1));
                this.of.h(r);
                this.oc.removeItem(r.c);
                this.nx.ax(r.c.c);
            }
            r = s;
        }
        for (var u = 0; u < b.count; u++) {
            if (!this.oc.containsKey(b._inner[u])) {
                this.of.f(b._inner[u]);
                var v = b._inner[u].b;
                v.propertyChanged = delegateCombine(v.propertyChanged, runOn(this, this.p1));
                this.oc.addItem(b._inner[u], this.of.d);
                m.add(b._inner[u]);
                k.add_1(b._inner[u]);
                this.n4 = true;
            }
        }
        for (var w = 0; w < c.count; w++) {
            if (!this.oc.containsKey(c._inner[w])) {
                this.of.f(c._inner[w]);
                this.oc.addItem(c._inner[w], this.of.d);
                var x = c._inner[w].b;
                x.propertyChanged = delegateCombine(x.propertyChanged, runOn(this, this.p1));
                m.add(c._inner[w]);
                k.add_1(c._inner[w]);
                this.n4 = true;
            }
        }
        if (this.n2 == true) {
            this.n2 = false;
            this.n4 = true;
        }
        if (this.oh.count > 0) {
            this.n4 = true;
            this.oh.clear();
            this.oe.clear();
        }
        r = this.of.c;
        while (r != null) {
            var y = this.n0(r.c);
            if (y == null) {
                return;
            }
            if (!Base.equalsStatic(y, r.c.c.c)) {
                var z = false;
                if (r.c.c.c == null) {
                    z = true;
                }
                var aa = r.c.c;
                aa.o = y.b;
                aa.p = y.c;
                if (!isNaN_(aa.o) && !isNaN_(aa.p)) {
                    aa.n = y.e;
                    aa.m = y.d;
                    if (aa.b == null) {
                        this.nx.p(aa);
                    }
                    if (z) {
                        this.nx.al(aa);
                    }
                    else {
                        this.nx.au(aa);
                    }
                }
            }
            r = r.a;
        }
        var ab = this.nx.ah();
        var ac = this.nx.q();
        if (this.n4 && (ab != 0 || ac)) {
            this.n4 = false;
            this.os = 0x7FFFFFFF;
            if (this.pb != null) {
                var ad = true;
                for (var ae = 0; ae < this.bs.series.count; ae++) {
                    var af = this.bs.series._inner[ae];
                    if (af.cj && typeCast(CalloutLayer.$, af) !== null) {
                        var ag = af;
                        if (ag.pb == this.pb) {
                            if (!ag.q8.equals1(this.nx.a0)) {
                                ad = false;
                                break;
                            }
                        }
                    }
                }
                if (ad) {
                    this.nx.az();
                }
                else {
                    this.nx.am();
                    this.nx.an();
                }
            }
            else {
                this.nx.az();
            }
        }
        else {
            this.nx.an();
        }
        var ah = this.of.c;
        while (ah != null) {
            var ai = ah.c;
            a.m.add1(ai);
            a.f.add(ai.b.bh);
            a.h.add(ai.b.bj);
            a.g.add(ai.b.bi);
            a.j.add(ai.b.backgroundPadding.c);
            a.l.add(ai.b.backgroundPadding.e);
            a.k.add(ai.b.backgroundPadding.d);
            a.i.add(ai.b.backgroundPadding.b);
            a.n.add(ai.b.x);
            a.o.add(ai.b.bk);
            a.p.add1(ai.b.am);
            a.q.add1(ai.b.z);
            var aj = ai.c;
            a.t.add(ai.c.o - (ai.c.g - ai.c.l));
            a.u.add(ai.c.p - (ai.c.h - ai.c.k));
            a.r.add(ai.c.g - ai.c.l);
            a.s.add(ai.c.h - ai.c.k);
            ah = ah.a;
        }
    };
    CalloutLayer.prototype.p3 = function () {
        if (this.nx != null) {
            var a = this.of.c;
            while (a != null) {
                var b = a.c.c;
                if (b != null) {
                    this.nx.ax(b);
                }
                a = a.a;
            }
            var c = this.nx;
            c.labelsMoved = delegateRemove(c.labelsMoved, runOn(this, this.p0));
            this.nx = null;
        }
        this.p2();
    };
    CalloutLayer.prototype.ny = 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.pb != null && c.pb == this.pb) {
                        if (c.nx != null) {
                            return c.nx;
                        }
                    }
                }
            }
        }
        return null;
    };
    CalloutLayer.prototype.ov = function () {
        return 20000;
    };
    CalloutLayer.prototype.ow = function () {
        return 300;
    };
    CalloutLayer.prototype.nz = function () {
        switch (this.ne) {
            case 0: return 2;
            case 2: return 1;
            case 3: return 2;
            case 1: return 0;
        }
        return 2;
    };
    CalloutLayer.prototype.p0 = function (a) {
        var b = this.nx.ah();
        if (b < this.os) {
            this.os = b;
            this.jl(false);
        }
    };
    CalloutLayer.prototype.n0 = function (a) {
        var b = this.nk;
        if (a.b.l != null) {
            b = a.b.l;
        }
        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.eh();
        var g = null;
        var h = null;
        for (var i = 0; i < e.length; i++) {
            if (e[i].ch) {
                h = e[i];
            }
            else {
                g = e[i];
            }
        }
        if (g == null || h == null) {
            return null;
        }
        if (!g.cg() || !h.cg()) {
            return null;
        }
        var j = 0;
        var k = 0;
        if (g.b4 && g.categoryMode != 0) {
            if (b.cr) {
                j = b.getOffsetValue();
            }
            else if (b.cl) {
                j = b.getOffsetValue();
            }
        }
        if (h.b4 && h.categoryMode != 0) {
            if (b.cl) {
                k = b.getOffsetValue();
            }
        }
        var l = new ScalerParams(0, this.bs.n2, g.i9, g.ca, g.i4());
        l.b = f;
        var m = new ScalerParams(0, this.bs.n2, h.i9, h.ca, h.i4());
        m.b = f;
        var n = g.dy(this.or(a.b.ab), l) + j;
        var o = h.dy(this.or(a.b.ac), m) + k;
        var p = new QuadTreeBoundingBox();
        p.b = n;
        p.c = o;
        p.e = 3;
        p.d = 3;
        p.g = a.b;
        return p;
    };
    CalloutLayer.prototype.or = function (a) {
        if (typeCast(Date_$type, a) !== null) {
            return a.getTime();
        }
        if (a == null) {
            return 0;
        }
        return a;
    };
    CalloutLayer.prototype.oj = function () {
        var a = new List$1(CalloutAnnotationWrapper.$, 0);
        for (var b = 0; b < this.oi.count; b++) {
            if (stringIsNullOrEmpty(this.oi._inner[b].b.am)) {
                continue;
            }
            if (this.oi._inner[b].c == null) {
                var c = new LabelCollisionInfo();
                this.oi._inner[b].c = c;
                var d = this.nh.cl(this.ox(this.oi._inner[b]), this.oi._inner[b].b.backgroundPadding);
                c.k = d.height / 2;
                c.l = d.width / 2;
            }
            var e = this.n0(this.oi._inner[b]);
            if (e == null || e.b < this.l8.left || e.b > this.l8.right || e.c < this.l8.top || e.c > this.l8.bottom) {
                continue;
            }
            a.add(this.oi._inner[b]);
        }
        return a;
    };
    CalloutLayer.prototype.ox = function (a) {
        return a.b.am;
    };
    CalloutLayer.prototype.mi = function (a) {
        if (!_super.prototype.mi.call(this, a)) {
            return false;
        }
        return true;
    };
    CalloutLayer.prototype.iw = function () {
        _super.prototype.iw.call(this);
        if (!this.aq.c && !this.ca()) {
            return;
        }
        if (this.n1) {
            this.n1 = false;
            this.p5();
        }
        if (this.ca()) {
            this.qa(this.md, false);
        }
        else {
            this.qa(this.mb, false);
        }
    };
    CalloutLayer.prototype.p6 = function () {
        if (!this.n3) {
            this.n3 = true;
            this.jl(true);
        }
    };
    CalloutLayer.prototype.p8 = function (a, b, c) {
        var d = false;
        if (this.n3) {
            this.n3 = false;
            d = true;
        }
        if (a.ch(this.og, this.ob, this.ot)) {
            var e = this.og;
            var _loop_1 = function (f) {
                var g = e._inner[f];
                var h = g.a.item != null ? g.a.item : g.a;
                var i = a;
                var j = new CalloutKey(h, i);
                var k = new CalloutAnnotationWrapper();
                var l = new CalloutAnnotation();
                k.b = l;
                l.key = j;
                var m = false;
                if (this_1.oc.containsKey(k)) {
                    k = this_1.oc.item(k).c;
                    l = k.b;
                    m = d;
                }
                else {
                    m = true;
                }
                var n = l.ab;
                var o = l.ac;
                if (this_1.or(n) != this_1.or(g.b)) {
                    l.xValue = g.b;
                }
                if (this_1.or(o) != this_1.or(g.c)) {
                    l.yValue = g.c;
                }
                l.series = a;
                var p = false;
                if (g.d != l.aw) {
                    l.aw = g.d;
                    p = true;
                }
                if (m || p) {
                    if (this_1.calloutLabelUpdating != null) {
                        var q = ((function () {
                            var $ret = new CalloutLabelUpdatingEventArgs();
                            $ret.c = l.ab;
                            $ret.d = l.ac;
                            $ret.item = h;
                            return $ret;
                        })());
                        this_1.calloutLabelUpdating(this_1, q);
                        if (q.b != null && !Base.equalsStatic(q.b, k.b.am)) {
                            var r = q.b;
                            k.b.text = r != null ? r.toString() : "";
                        }
                    }
                    else {
                        if (g.d != null) {
                            l.text = g.d;
                        }
                    }
                }
                if (l.am == null) {
                    return "continue";
                }
                if (m || p) {
                    if (this_1.calloutContentUpdating != null) {
                        var s = ((function () {
                            var $ret = new CalloutContentUpdatingEventArgs();
                            $ret.c = l.ab;
                            $ret.d = l.ac;
                            $ret.item = h;
                            $ret.a = h;
                            return $ret;
                        })());
                        this_1.calloutContentUpdating(this_1, s);
                        if (s.a != null && s.a != k.b.z) {
                            k.b.content = s.a;
                        }
                    }
                    else {
                        if (h != null && h != k.b.z) {
                            k.b.content = h;
                        }
                    }
                }
                if (m) {
                    this_1.qc(k);
                }
                if (k.c == null) {
                    var t = new LabelCollisionInfo();
                    k.c = t;
                    var u = this_1.nh.cl(this_1.ox(k), k.b.backgroundPadding);
                    t.k = u.height / 2;
                    t.l = u.width / 2;
                }
                var v = this_1.n0(k);
                if (v == null || v.b < this_1.l8.left || v.b > this_1.l8.right || v.c < this_1.l8.top || v.c > this_1.l8.bottom) {
                    return "continue";
                }
                c.add(k);
            };
            var this_1 = this;
            for (var f = 0; f < this.og.count; f++) {
                _loop_1(f);
            }
        }
    };
    CalloutLayer.prototype.bd = function () {
        return 1;
    };
    CalloutLayer.prototype.ar = function (a, b) {
        var c = this.nx.d(a, b);
        if (c == null) {
            return null;
        }
        return c.u;
    };
    CalloutLayer.prototype.dh = function (a, b) {
        if (this.nx == null) {
            return false;
        }
        return this.nx.d(a, b) != null;
    };
    CalloutLayer.prototype.qa = function (a, b) {
        var e_3, _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.nh.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.nh.ce(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.nh.cf(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.nh.b6.c)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var i = _c.value;
                if (!d.contains(i)) {
                    h.add(i);
                }
            }
        }
        catch (e_3_1) {
            e_3 = { error: e_3_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_3)
                    throw e_3.error;
            }
        }
        for (var j = 0; j < h.count; j++) {
            this.nh.b6.g(h._inner[j]);
        }
    };
    CalloutLayer.prototype.m0 = function (a, b) {
        _super.prototype.m0.call(this, a, b);
        if (this.ca()) {
            this.qa(this.md, true);
        }
        else {
            this.qa(this.mb, false);
        }
    };
    CalloutLayer.prototype.c8 = function () {
        return true;
    };
    CalloutLayer.prototype.i7 = function (a, b, c, d) {
        _super.prototype.i7.call(this, a, b, c, d);
        switch (b) {
            case CalloutLayer.$$p[21]:
                this.nl = null;
                this.nh.cd();
                this.jl(true);
                break;
            case CalloutLayer.$$p[20]:
                this.jl(true);
                break;
            case CalloutLayer.$$p[13]:
                this.jl(true);
                break;
            case "SeriesViewer":
                if (c != null) {
                    var e = c;
                    e.seriesAnimating = delegateRemove(e.seriesAnimating, runOn(this, this.p9));
                }
                if (d != null) {
                    var f = d;
                    f.seriesAnimating = delegateCombine(f.seriesAnimating, runOn(this, this.p9));
                }
                if (d == null) {
                    this.p3();
                }
                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.p4();
                break;
            case CalloutLayer.$$p[19]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nu);
                    this.nu = this.by(this.pn);
                }
                break;
            case "LabelColumn":
                this.p4();
                break;
            case CalloutLayer.$$p[14]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.ns);
                    this.ns = this.by(this.pe);
                }
                break;
            case "ContentColumn":
                this.p4();
                break;
            case CalloutLayer.$$p[23]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nv);
                    this.nv = stringIsNullOrEmpty(this.pu) == false ? this.by(this.pu) : null;
                }
                break;
            case "XColumn":
                this.p4();
                break;
            case CalloutLayer.$$p[24]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nw);
                    this.nw = this.by(this.px);
                }
                break;
            case "YColumn":
                this.p4();
                break;
            case CalloutLayer.$$p[18]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nt);
                    this.nt = this.by(this.pk);
                }
                break;
            case "KeyColumn":
                this.p4();
                break;
            case "FastItemsSource":
                this.n2 = true;
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.nu);
                    c.deregisterColumn(this.ns);
                    c.deregisterColumn(this.nv);
                    c.deregisterColumn(this.nw);
                    c.deregisterColumn(this.nt);
                    this.nu = null;
                    this.ns = null;
                    this.nv = null;
                    this.nw = null;
                    this.nt = null;
                    this.oi.clear();
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.nu = this.by(this.pn);
                    this.ns = this.by(this.pe);
                    if (stringIsNullOrEmpty(this.pu) == false) {
                        this.nv = this.by(this.pu);
                    }
                    this.nw = this.by(this.px);
                    this.nt = this.by(this.pk);
                }
                this.p4();
                break;
        }
    };
    CalloutLayer.prototype.p9 = function (a) {
        if (a.cj) {
            return;
        }
        if ((a == this.nk || this.nk == null) && this.n8) {
            this.jl(false);
        }
    };
    CalloutLayer.prototype.p4 = function () {
        if (this.n1 == false) {
            this.n1 = true;
            this.jl(false);
        }
    };
    CalloutLayer.prototype.p2 = function () {
        this.nh.b6.clear();
        this.of.g();
        this.oc.clear();
    };
    CalloutLayer.prototype.p5 = function () {
        if (this.nw == null || this.nu == null) {
            var a = this.of.c;
            while (a != null) {
                this.qc(a.c);
                a = a.a;
            }
            return;
        }
        var b = this.od();
        for (var c = 0; c < this.nw.count; c++) {
            var d = void 0;
            if (this.oi.count <= c) {
                var e = new CalloutAnnotation();
                d = new CalloutAnnotationWrapper();
                d.b = e;
                d.b.series = this.nk;
                this.oi.add(d);
            }
            else {
                d = this.oi._inner[c];
            }
            this.qb(c, b);
        }
    };
    CalloutLayer.$t = markType(CalloutLayer, 'CalloutLayer', AnnotationLayer.$);
    CalloutLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CalloutLayer, 'raisePropertyChanged', ['AutoCalloutLabelPrecision:ot:qd', [1, 5], 'CalloutBackground:q2:qe', [Brush.$, null], 'CalloutCollisionMode:ne:qf', [CalloutCollisionMode_$type, enumGetBox(CalloutCollisionMode_$type, 3)], 'CalloutInterpolatedValuePrecision:ou:qg', [1, -1], 'CalloutLeaderBrush:q3:qh', [Brush.$, null], 'CalloutOutline:q4:qi', [Brush.$, null], 'CalloutPaddingBottom:ol:qj', [1, NaN], 'CalloutPaddingLeft:om:qk', [1, NaN], 'CalloutPaddingRight:on:ql', [1, NaN], 'CalloutPaddingTop:oo:qm', [1, NaN], 'CalloutPositionPadding:op:qn', [1, 10], 'CalloutStrokeThickness:oq:qo', [1, NaN], 'CalloutTextColor:q5:qp', [Brush.$, null], 'CollisionChannel:pb:qq', [2, null], 'ContentMemberPath:pe:qr', [2, null], 'IsAutoCalloutBehaviorEnabled:n8:qs', [0, false], 'IsCalloutOffsettingEnabled:n9:qt', [0, true], 'IsCustomCalloutStyleEnabled:oa:qu', [0, false], 'KeyMemberPath:pk:qv', [2, null], 'LabelMemberPath:pn:qw', [2, null], 'TargetSeries:nk:qx', [Series.$, null], 'TextStyle:pq:qy', [2, null], 'UseValueForAutoCalloutLabels:ob:qz', [0, true], 'XMemberPath:pu:q0', [2, null], 'YMemberPath:px:q1', [2, null]]);
    return CalloutLayer;
}(AnnotationLayer));
export { CalloutLayer };
/**
 * @hidden
 */
var CalloutLayerView = /** @class */ /*@__PURE__*/ (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.ca);
            $ret.disactivate = runOn(_this, _this.cc);
            $ret.destroy = runOn(_this, _this.cb);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.b3 = function () {
        var a = new CalloutView(this);
        this.b7.add(a);
        return a;
    };
    CalloutLayerView.prototype.ca = function (a) {
        a.w = 0;
    };
    CalloutLayerView.prototype.cc = function (a) {
        a.w = 1;
    };
    CalloutLayerView.prototype.cb = function (a) {
        this.b7.remove(a);
    };
    CalloutLayerView.prototype.ck = function (a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.l(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.nm != null) {
            return this.b1.nm;
        }
        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.cm = function (a) {
        this.h.ac(this.b5());
        this.b8 = this.b9();
        return new Size(1, this.h.f(a.ak), this.b8);
    };
    CalloutLayerView.prototype.b9 = function () {
        var a = this.b5();
        if (isNaN_(this.b8)) {
            var b = FontUtil.getCurrentFontHeight(this.e.bs.b1.i.ae, a);
            this.b8 = b;
        }
        return this.b8;
    };
    CalloutLayerView.prototype.cl = 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.b1.i.ae);
    };
    CalloutLayerView.prototype.ce = function (a, b, c) {
        a.d = b;
        a.e = c;
    };
    CalloutLayerView.prototype.cf = function (a, b, c) {
        a.i(this.e, b, c);
    };
    CalloutLayerView.prototype.cg = function (a) {
        if (a != null) {
            return this.ck(a.le);
        }
        return this.e.le;
    };
    CalloutLayerView.prototype.cj = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.ci = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    };
    CalloutLayerView.prototype.ch = function (a) {
        if (a != null) {
            return this.ck(a.lb);
        }
        return this.e.lb;
    };
    CalloutLayerView.prototype.cd = function () {
        this.b8 = NaN;
    };
    CalloutLayerView.$t = markType(CalloutLayerView, 'CalloutLayerView', AnnotationLayerView.$);
    return CalloutLayerView;
}(AnnotationLayerView));
export { CalloutLayerView };
/**
 * @hidden
 */
var CalloutView = /** @class */ /*@__PURE__*/ (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.cm(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 };
//# sourceMappingURL=CalloutLayer_combined.js.map
