/*
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 { 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
 */
export let CalloutLayer = /*@__PURE__*/ (() => {
    class CalloutLayer extends AnnotationLayer {
        constructor() {
            super();
            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;
            let a = new CalloutLayerFrame();
            let b = new CalloutLayerFrame();
            let c = new CalloutLayerFrame();
            let d = this.fi / 1000;
            this.mc = a;
            this.mb = b;
            this.md = c;
            this.ab = CalloutLayer.$;
        }
        pz(a, b) {
            this.oi.clear();
            this.jl(false);
        }
        h6(a, b, c, d) {
            super.h6(a, b, c, d);
            let e = this.od();
            switch (a) {
                case 3:
                    this.qb(b, e);
                    break;
                case 1:
                    for (let f = b; f < b + c; f++) {
                        let g = new CalloutAnnotation();
                        let 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 (let i = b; i < b + c; i++) {
                        this.qb(i, e);
                    }
                    break;
                case 4:
                    this.oi.clear();
                    for (let j = 0; j < this.bz.count; j++) {
                        let k = new CalloutAnnotation();
                        let l = new CalloutAnnotationWrapper();
                        l.b = k;
                        l.b.series = this.nk;
                        this.oi.add(l);
                        this.qb(j, e);
                    }
                    break;
            }
            this.jl(true);
        }
        da(a) {
            return false;
        }
        od() {
            let a = new Dictionary$2(String_$type, Series.$, 0);
            if (this.bs != null) {
                for (let b = 0; b < this.bs.series.count; b++) {
                    let c = this.bs.series._inner[b];
                    if (c.name != null && !a.containsKey(c.name)) {
                        a.addItem(c.name, c);
                    }
                }
            }
            return a;
        }
        qb(a, b) {
            if (this.nw == null || this.nu == null) {
                return;
            }
            let c = a;
            if (this.nv != null) {
                c = this.nv.item(a);
            }
            let d = this.nw.item(a);
            let e = this.nu.item(a);
            let 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) {
                let g = ((() => {
                    let $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)) {
                    let 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) {
                let i = ((() => {
                    let $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);
        }
        qc(a) {
            let 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;
            }
            let c = this.q2 != null ? this.q2 : this.nh.cg(a.b.l);
            let d = this.q5 != null ? this.q5 : this.nh.cj();
            let e = this.q4 != null ? this.q4 : this.nh.ci();
            let f = this.q3 != null ? this.q3 : this.nh.ch(a.b.l);
            let g = isNaN_(this.oq) ? 0 : this.oq;
            if (this.oa && this.calloutStyleUpdating != null) {
                let 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;
        }
        fs(a, b) {
            let 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.fs(a, b);
        }
        get nu() {
            return this.np;
        }
        set nu(a) {
            if (this.np != a) {
                let b = this.np;
                this.np = a;
                this.raisePropertyChanged("LabelColumn", b, this.np);
            }
        }
        get nv() {
            return this.nq;
        }
        set nv(a) {
            if (this.nq != a) {
                let b = this.nq;
                this.nq = a;
                this.raisePropertyChanged("XColumn", b, this.nq);
            }
        }
        get nw() {
            return this.nr;
        }
        set nw(a) {
            if (this.nr != a) {
                let b = this.nr;
                this.nr = a;
                this.raisePropertyChanged("YColumn", b, this.nr);
            }
        }
        get nt() {
            return this.no;
        }
        set nt(a) {
            if (this.no != a) {
                let b = this.no;
                this.no = a;
                this.raisePropertyChanged("KeyColumn", b, this.no);
            }
        }
        get ns() {
            return this.nn;
        }
        set ns(a) {
            if (this.nn != a) {
                let b = this.nn;
                this.nn = a;
                this.raisePropertyChanged("ContentColumn", b, this.nn);
            }
        }
        p1(a, b) {
            if (b.propertyName == CalloutAnnotation.$$p[13] || b.propertyName == CalloutAnnotation.$$p[14]) {
                let c = a.k;
                if (!this.oe.contains(c)) {
                    this.oe.add_1(c);
                    this.oh.add(c);
                    this.jl(false);
                }
            }
        }
        bf() {
            return new CalloutLayerView(this);
        }
        i2(a) {
            super.i2(a);
            this.nh = a;
        }
        get q9() {
            return new Thickness(1, this.om, this.oo, this.on, this.ol);
        }
        get nm() {
            if (this.nl == null) {
                this.nl = FontUtil.toFontInfo(this.e4, this.pq);
            }
            return this.nl;
        }
        mv(a, b) {
            if (this.nk == null || this.nk == a) {
                if (!this.aq.c) {
                    this.jl(b);
                }
            }
        }
        mx(a, b) {
            super.mx(a, b);
            let 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();
            let d = this.oj();
            let e = new List$1(CalloutAnnotationWrapper.$, 0);
            if (this.n8) {
                if (this.mi(this.nk)) {
                    this.p8(this.nk, c, e);
                }
                else {
                    for (let f of fromEnum(this.bs.series)) {
                        if (this.mi(f)) {
                            this.p8(f, c, e);
                        }
                    }
                }
            }
            this.p7(c, d, e);
        }
        j1(a, b) {
            super.j1(a, b);
            let c = b.width - this.q7.width;
            let d = b.height - this.q7.height;
            let 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;
            }
        }
        j0(a, b) {
            super.j0(a, b);
            if (!a.equals1(b)) {
                this.n5 = true;
            }
        }
        get q8() {
            return this.q6;
        }
        set q8(a) {
            this.q6 = a;
        }
        p7(a, b, c) {
            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) {
                let d = this.ny();
                if (d != null) {
                    this.nx = d;
                    let e = this.nx;
                    e.labelsMoved = delegateCombine(e.labelsMoved, runOn(this, this.p0));
                }
                else {
                    let f = this.l0(this.bi);
                    let g = 0;
                    if (this.nk != null) {
                        if (this.nk.isVertical) {
                            g = 2;
                        }
                    }
                    else {
                        let h = false;
                        if (this.bs != null && this.bs.series.count > 0) {
                            h = true;
                            for (let i of fromEnum(this.bs.series)) {
                                if (!i.cj) {
                                    if (!i.isVertical) {
                                        h = false;
                                    }
                                }
                            }
                        }
                        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;
                    }
                    let 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;
            }
            let k = new HashSet$1(CalloutAnnotationWrapper.$, 0);
            let l = new HashSet$1(CalloutAnnotationWrapper.$, 0);
            let m = new List$1(CalloutAnnotationWrapper.$, 0);
            let n = new List$1(CalloutAnnotationWrapper.$, 0);
            let o = new HashSet$1(CalloutAnnotationWrapper.$, 0);
            for (let p = 0; p < b.count; p++) {
                o.add_1(b._inner[p]);
            }
            for (let q = 0; q < c.count; q++) {
                o.add_1(c._inner[q]);
            }
            let r = this.of.c;
            while (r != null) {
                let s = r.a;
                if (!o.contains(r.c)) {
                    n.add(r.c);
                    l.add_1(r.c);
                    let 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 (let u = 0; u < b.count; u++) {
                if (!this.oc.containsKey(b._inner[u])) {
                    this.of.f(b._inner[u]);
                    let 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 (let 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);
                    let 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) {
                let y = this.n0(r.c);
                if (y == null) {
                    return;
                }
                if (!Base.equalsStatic(y, r.c.c.c)) {
                    let z = false;
                    if (r.c.c.c == null) {
                        z = true;
                    }
                    let 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;
            }
            let ab = this.nx.ah();
            let ac = this.nx.q();
            if (this.n4 && (ab != 0 || ac)) {
                this.n4 = false;
                this.os = 0x7FFFFFFF;
                if (this.pb != null) {
                    let ad = true;
                    for (let ae = 0; ae < this.bs.series.count; ae++) {
                        let af = this.bs.series._inner[ae];
                        if (af.cj && typeCast(CalloutLayer.$, af) !== null) {
                            let 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();
            }
            let ah = this.of.c;
            while (ah != null) {
                let 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);
                let 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;
            }
        }
        p3() {
            if (this.nx != null) {
                let a = this.of.c;
                while (a != null) {
                    let b = a.c.c;
                    if (b != null) {
                        this.nx.ax(b);
                    }
                    a = a.a;
                }
                let c = this.nx;
                c.labelsMoved = delegateRemove(c.labelsMoved, runOn(this, this.p0));
                this.nx = null;
            }
            this.p2();
        }
        ny() {
            if (this.bs == null) {
                return null;
            }
            for (let a = 0; a < this.bs.series.count; a++) {
                let b = this.bs.series._inner[a];
                if (b.cj && typeCast(CalloutLayer.$, b) !== null) {
                    let c = b;
                    if (c != this) {
                        if (c.pb != null && c.pb == this.pb) {
                            if (c.nx != null) {
                                return c.nx;
                            }
                        }
                    }
                }
            }
            return null;
        }
        ov() {
            return 20000;
        }
        ow() {
            return 300;
        }
        nz() {
            switch (this.ne) {
                case 0: return 2;
                case 2: return 1;
                case 3: return 2;
                case 1: return 0;
            }
            return 2;
        }
        p0(a) {
            let b = this.nx.ah();
            if (b < this.os) {
                this.os = b;
                this.jl(false);
            }
        }
        n0(a) {
            let b = this.nk;
            if (a.b.l != null) {
                b = a.b.l;
            }
            if (b == null) {
                for (let c = 0; c < this.bs.series.count; c++) {
                    let d = this.bs.series._inner[c];
                    if (!d.cj) {
                        b = d;
                        break;
                    }
                }
            }
            if (b == null) {
                return null;
            }
            let e = b.ag();
            let f = b.eh();
            let g = null;
            let h = null;
            for (let 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;
            }
            let j = 0;
            let 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();
                }
            }
            let l = new ScalerParams(0, this.bs.n2, g.i9, g.ca, g.i4());
            l.b = f;
            let m = new ScalerParams(0, this.bs.n2, h.i9, h.ca, h.i4());
            m.b = f;
            let n = g.dy(this.or(a.b.ab), l) + j;
            let o = h.dy(this.or(a.b.ac), m) + k;
            let p = new QuadTreeBoundingBox();
            p.b = n;
            p.c = o;
            p.e = 3;
            p.d = 3;
            p.g = a.b;
            return p;
        }
        or(a) {
            if (typeCast(Date_$type, a) !== null) {
                return a.getTime();
            }
            if (a == null) {
                return 0;
            }
            return a;
        }
        oj() {
            let a = new List$1(CalloutAnnotationWrapper.$, 0);
            for (let b = 0; b < this.oi.count; b++) {
                if (stringIsNullOrEmpty(this.oi._inner[b].b.am)) {
                    continue;
                }
                if (this.oi._inner[b].c == null) {
                    let c = new LabelCollisionInfo();
                    this.oi._inner[b].c = c;
                    let 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;
                }
                let 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;
        }
        ox(a) {
            return a.b.am;
        }
        mi(a) {
            if (!super.mi(a)) {
                return false;
            }
            return true;
        }
        iw() {
            super.iw();
            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);
            }
        }
        p6() {
            if (!this.n3) {
                this.n3 = true;
                this.jl(true);
            }
        }
        p8(a, b, c) {
            let d = false;
            if (this.n3) {
                this.n3 = false;
                d = true;
            }
            if (a.ch(this.og, this.ob, this.ot)) {
                let e = this.og;
                for (let f = 0; f < this.og.count; f++) {
                    let g = e._inner[f];
                    let h = g.a.item != null ? g.a.item : g.a;
                    let i = a;
                    let j = new CalloutKey(h, i);
                    let k = new CalloutAnnotationWrapper();
                    let l = new CalloutAnnotation();
                    k.b = l;
                    l.key = j;
                    let m = false;
                    if (this.oc.containsKey(k)) {
                        k = this.oc.item(k).c;
                        l = k.b;
                        m = d;
                    }
                    else {
                        m = true;
                    }
                    let n = l.ab;
                    let o = l.ac;
                    if (this.or(n) != this.or(g.b)) {
                        l.xValue = g.b;
                    }
                    if (this.or(o) != this.or(g.c)) {
                        l.yValue = g.c;
                    }
                    l.series = a;
                    let p = false;
                    if (g.d != l.aw) {
                        l.aw = g.d;
                        p = true;
                    }
                    if (m || p) {
                        if (this.calloutLabelUpdating != null) {
                            let q = ((() => {
                                let $ret = new CalloutLabelUpdatingEventArgs();
                                $ret.c = l.ab;
                                $ret.d = l.ac;
                                $ret.item = h;
                                return $ret;
                            })());
                            this.calloutLabelUpdating(this, q);
                            if (q.b != null && !Base.equalsStatic(q.b, k.b.am)) {
                                let r = q.b;
                                k.b.text = r != null ? r.toString() : "";
                            }
                        }
                        else {
                            if (g.d != null) {
                                l.text = g.d;
                            }
                        }
                    }
                    if (l.am == null) {
                        continue;
                    }
                    if (m || p) {
                        if (this.calloutContentUpdating != null) {
                            let s = ((() => {
                                let $ret = new CalloutContentUpdatingEventArgs();
                                $ret.c = l.ab;
                                $ret.d = l.ac;
                                $ret.item = h;
                                $ret.a = h;
                                return $ret;
                            })());
                            this.calloutContentUpdating(this, 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.qc(k);
                    }
                    if (k.c == null) {
                        let t = new LabelCollisionInfo();
                        k.c = t;
                        let u = this.nh.cl(this.ox(k), k.b.backgroundPadding);
                        t.k = u.height / 2;
                        t.l = u.width / 2;
                    }
                    let v = this.n0(k);
                    if (v == null || v.b < this.l8.left || v.b > this.l8.right || v.c < this.l8.top || v.c > this.l8.bottom) {
                        continue;
                    }
                    c.add(k);
                }
            }
        }
        bd() {
            return 1;
        }
        ar(a, b) {
            let c = this.nx.d(a, b);
            if (c == null) {
                return null;
            }
            return c.u;
        }
        dh(a, b) {
            if (this.nx == null) {
                return false;
            }
            return this.nx.d(a, b) != null;
        }
        qa(a, b) {
            let c = 0;
            let d = new HashSet$1(CalloutAnnotationWrapper.$, 0);
            for (c = 0; c < a.p.count; c++) {
                let e = a.m._inner[c];
                if (isNaN_(a.t._inner[c]) || isNaN_(a.u._inner[c])) {
                    continue;
                }
                let f = this.nh.b6.item(e);
                d.add_1(e);
                if (f.f != a.p._inner[c]) {
                    f.f = a.p._inner[c];
                    let 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] };
            }
            let h = new List$1(CalloutAnnotationWrapper.$, 0);
            for (let i of fromEnum(this.nh.b6.c)) {
                if (!d.contains(i)) {
                    h.add(i);
                }
            }
            for (let j = 0; j < h.count; j++) {
                this.nh.b6.g(h._inner[j]);
            }
        }
        m0(a, b) {
            super.m0(a, b);
            if (this.ca()) {
                this.qa(this.md, true);
            }
            else {
                this.qa(this.mb, false);
            }
        }
        c8() {
            return true;
        }
        i7(a, b, c, d) {
            super.i7(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) {
                        let e = c;
                        e.seriesAnimating = delegateRemove(e.seriesAnimating, runOn(this, this.p9));
                    }
                    if (d != null) {
                        let 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;
            }
        }
        p9(a) {
            if (a.cj) {
                return;
            }
            if ((a == this.nk || this.nk == null) && this.n8) {
                this.jl(false);
            }
        }
        p4() {
            if (this.n1 == false) {
                this.n1 = true;
                this.jl(false);
            }
        }
        p2() {
            this.nh.b6.clear();
            this.of.g();
            this.oc.clear();
        }
        p5() {
            if (this.nw == null || this.nu == null) {
                let a = this.of.c;
                while (a != null) {
                    this.qc(a.c);
                    a = a.a;
                }
                return;
            }
            let b = this.od();
            for (let c = 0; c < this.nw.count; c++) {
                let d;
                if (this.oi.count <= c) {
                    let 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 = /*@__PURE__*/ markType(CalloutLayer, 'CalloutLayer', AnnotationLayer.$);
    CalloutLayer.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CalloutLayer, 'raisePropertyChanged', ['AutoCalloutLabelPrecision:ot:qd', [1, 5], 'CalloutBackground:q2:qe', [Brush.$, null], 'CalloutCollisionMode:ne:qf', [CalloutCollisionMode_$type, /*@__PURE__*/ 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;
})();
/**
 * @hidden
 */
export let CalloutLayerView = /*@__PURE__*/ (() => {
    class CalloutLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            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);
        }
        ap() {
            super.ap();
            this.b6 = ((() => {
                let $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;
            })());
        }
        b3() {
            let a = new CalloutView(this);
            this.b7.add(a);
            return a;
        }
        ca(a) {
            a.w = 0;
        }
        cc(a) {
            a.w = 1;
        }
        cb(a) {
            this.b7.remove(a);
        }
        ck(a) {
            if (a == null) {
                return a;
            }
            return BrushUtil.l(a, 0.1);
        }
        a3(a, b) {
            super.a3(a, b);
            a.ac(this.b5());
            if (a.d && !b) {
                for (let c = 0; c < this.b7.count; c++) {
                    let d = this.b7._inner[c];
                    if (d.w == 0) {
                        d.h(a);
                    }
                }
            }
        }
        b5() {
            if (this.b1.nm != null) {
                return this.b1.nm;
            }
            return this.e.bs.getFontInfo();
        }
        ai(a) {
            super.ai(a);
            for (let b = 0; b < this.b7.count; b++) {
                let c = this.b7._inner[b];
                if (c.w != 0) {
                    continue;
                }
                c.g(this.b1, this.b5(), a);
            }
        }
        cm(a) {
            this.h.ac(this.b5());
            this.b8 = this.b9();
            return new Size(1, this.h.f(a.ak), this.b8);
        }
        b9() {
            let a = this.b5();
            if (isNaN_(this.b8)) {
                let b = FontUtil.getCurrentFontHeight(this.e.bs.b1.i.ae, a);
                this.b8 = b;
            }
            return this.b8;
        }
        cl(a, b) {
            if (this.b2 == null) {
                this.b2 = new CalloutView(this);
            }
            this.b2.f = a;
            this.b2.v = b;
            let c = this.b2.s();
            this.b2.f = null;
            return c;
        }
        b4() {
            return new DOMExecutionContext(this.e.bs.b1.i.ae);
        }
        ce(a, b, c) {
            a.d = b;
            a.e = c;
        }
        cf(a, b, c) {
            a.i(this.e, b, c);
        }
        cg(a) {
            if (a != null) {
                return this.ck(a.le);
            }
            return this.e.le;
        }
        cj() {
            return ((() => {
                let $ret = new Brush();
                $ret.color = Color.u(255, 255, 255, 255);
                return $ret;
            })());
        }
        ci() {
            return ((() => {
                let $ret = new Brush();
                $ret.color = Color.u(255, 255, 255, 255);
                return $ret;
            })());
        }
        ch(a) {
            if (a != null) {
                return this.ck(a.lb);
            }
            return this.e.lb;
        }
        cd() {
            this.b8 = NaN;
        }
    }
    CalloutLayerView.$t = /*@__PURE__*/ markType(CalloutLayerView, 'CalloutLayerView', AnnotationLayerView.$);
    return CalloutLayerView;
})();
/**
 * @hidden
 */
export let CalloutView = /*@__PURE__*/ (() => {
    class CalloutView extends Base {
        constructor(a) {
            super();
            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 = ((() => {
                let $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;
        }
        h(a) {
            a.z();
            a.af(this.d, this.e);
            let 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();
        }
        get p() {
            return this.o;
        }
        set p(a) {
            if (this.o.x != a.x || this.o.y != a.y) {
                let b = this.s();
                let c = b.height;
                let d = b.width;
                this.o = a;
                let e = CalloutViewHelper.b(this.p, d, c, this.q);
                this.t = e;
            }
        }
        get n() {
            return this.j.am;
        }
        set n(a) {
            this.j.am = a;
        }
        get m() {
            return this.r._stroke;
        }
        set m(a) {
            this.r._stroke = a;
        }
        get l() {
            return this.q._stroke;
        }
        set l(a) {
            this.q._stroke = a;
        }
        get k() {
            return this.r._fill;
        }
        set k(a) {
            this.r._fill = a;
        }
        get c() {
            return this.r.ac;
        }
        set c(a) {
            this.r.ac = a;
        }
        get v() {
            return this.u;
        }
        set v(a) {
            this.u = a;
        }
        get f() {
            return this.j.ak;
        }
        set f(a) {
            if (a == null) {
                this.j.ak = "";
            }
            else {
                this.j.ak = a.toString();
            }
            let b = this.s();
            let c = b.height;
            let d = b.width;
            let e = CalloutViewHelper.b(this.p, d, c, this.q);
            this.t = e;
        }
        s() {
            let 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);
        }
        i(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;
            }
        }
        g(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 = /*@__PURE__*/ markType(CalloutView, 'CalloutView');
    return CalloutView;
})();
//# sourceMappingURL=CalloutLayer_combined.js.map
