/*
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/ES2015/DependencyProperty";
import { Base, Type, String_$type, typeCast, enumGetBox, fromEnum, runOn, delegateCombine, delegateRemove, Date_$type, Point_$type, markType } from "igniteui-react-core/ES2015/type";
import { Series } from "./Series";
import { Brush } from "igniteui-react-core/ES2015/Brush";
import { Thickness } from "igniteui-react-core/ES2015/Thickness";
import { CalloutCollisionMode_$type } from "./CalloutCollisionMode";
import { FontUtil } from "igniteui-react-core/ES2015/FontUtil";
import { Rect } from "igniteui-react-core/ES2015/Rect";
import { CalloutLayerFrame } from "./CalloutLayerFrame";
import { HashSet$1 } from "igniteui-react-core/ES2015/HashSet$1";
import { CalloutAnnotationWrapper } from "./CalloutAnnotationWrapper";
import { List$1 } from "igniteui-react-core/ES2015/List$1";
import { LinkedList$1 } from "igniteui-react-core/ES2015/LinkedList$1";
import { Dictionary$2 } from "igniteui-react-core/ES2015/Dictionary$2";
import { LinkedListNode$1 } from "igniteui-react-core/ES2015/LinkedListNode$1";
import { LabelCollisionManager } from "igniteui-react-core/ES2015/LabelCollisionManager";
import { SeriesPointOfInterest } from "./SeriesPointOfInterest";
import { CalloutAnnotation } from "./CalloutAnnotation";
import { IFastItemsSource_$type } from "igniteui-react-core/ES2015/IFastItemsSource";
import { CalloutSeriesSelectingEventArgs } from "./CalloutSeriesSelectingEventArgs";
import { CalloutStyleUpdatingEventArgs } from "./CalloutStyleUpdatingEventArgs";
import { QuadTreeBoundingBox } from "igniteui-react-core/ES2015/QuadTreeBoundingBox";
import { LabelCollisionInfo } from "igniteui-react-core/ES2015/LabelCollisionInfo";
import { ScalerParams } from "./ScalerParams";
import { Size } from "igniteui-react-core/ES2015/Size";
import { CalloutContentUpdatingEventArgs } from "./CalloutContentUpdatingEventArgs";
import { CalloutLabelUpdatingEventArgs } from "./CalloutLabelUpdatingEventArgs";
import { CalloutKey } from "./CalloutKey";
import { DataContext } from "igniteui-react-core/ES2015/DataContext";
import { HashPool$2 } from "igniteui-react-core/ES2015/HashPool$2";
import { PropertyMetadata } from "igniteui-react-core/ES2015/PropertyMetadata";
import { isNaN_ } from "igniteui-react-core/ES2015/number";
import { stringIsNullOrEmpty } from "igniteui-react-core/ES2015/string";
import { FastItemObjectColumn } from "igniteui-react-core/ES2015/FastItemObjectColumn";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { BrushUtil } from "igniteui-react-core/ES2015/BrushUtil";
import { TextBlock } from "igniteui-react-core/ES2015/TextBlock";
import { DOMExecutionContext } from "igniteui-react-core/ES2015/DOMExecutionContext";
import { Color } from "igniteui-react-core/ES2015/Color";
import { Line } from "igniteui-react-core/ES2015/Line";
import { CalloutViewHelper } from "./CalloutViewHelper";
import { Rectangle } from "igniteui-react-core/ES2015/Rectangle";
import { TranslateTransform } from "igniteui-react-core/ES2015/TranslateTransform";
export class CalloutLayer extends AnnotationLayer {
    constructor() {
        super();
        this.calloutStyleUpdating = null;
        this.m4 = null;
        this.m5 = null;
        this.m6 = null;
        this.m3 = null;
        this.m2 = null;
        this.ns = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        this.nv = new List$1(CalloutAnnotationWrapper.$, 0);
        this.nw = new List$1(CalloutAnnotationWrapper.$, 0);
        this.m0 = null;
        this.nt = new LinkedList$1(CalloutAnnotationWrapper.$);
        this.nq = new Dictionary$2(CalloutAnnotationWrapper.$, LinkedListNode$1.$.specialize(CalloutAnnotationWrapper.$), 0);
        this.nc = null;
        this.ql = new Rect(0, 0, 0, 1, 1);
        this.ni = false;
        this.n6 = 0;
        this.qk = Rect.empty;
        this.nh = false;
        this.calloutContentUpdating = null;
        this.calloutLabelUpdating = null;
        this.calloutSeriesSelecting = null;
        this.nu = new List$1(SeriesPointOfInterest.$, 0);
        this.nk = false;
        this.nl = false;
        this.ny = 0;
        this.nj = false;
        this.ng = true;
        FastItemObjectColumn.k();
        this.lz = true;
        let a = new CalloutLayerFrame();
        let b = new CalloutLayerFrame();
        let c = new CalloutLayerFrame();
        let d = this.fe / 1000;
        this.lt = a;
        this.ls = b;
        this.lu = c;
        this.ab = CalloutLayer.$;
    }
    pd(a, b) {
        this.nw.clear();
        this.i4(false);
    }
    hr(a, b, c, d) {
        super.hr(a, b, c, d);
        let e = this.nr();
        switch (a) {
            case 3:
                this.pp(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.mz;
                    this.nw.insert(f, h);
                    this.pp(f, e);
                }
                break;
            case 0:
                this.nw.v(b, c);
                break;
            case 2:
                for (let i = b; i < b + c; i++) {
                    this.pp(i, e);
                }
                break;
            case 4:
                this.nw.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.mz;
                    this.nw.add(l);
                    this.pp(j, e);
                }
                break;
        }
        this.i4(true);
    }
    c8(a) {
        return false;
    }
    nr() {
        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;
    }
    pp(a, b) {
        if (this.nb == null || this.m9 == null) {
            return;
        }
        let c = a;
        if (this.na != null) {
            c = this.na.item(a);
        }
        let d = this.nb.item(a);
        let e = this.m9.item(a);
        let f = this.nw._inner[a];
        f.b.xValue = c;
        f.b.yValue = d;
        f.b.text = e != null ? e.toString() : "";
        if (this.m8 != null) {
            f.b.key = this.m8.item(a);
        }
        if (this.m7 != null) {
            f.b.content = this.m7.item(a);
        }
        else {
            f.b.content = this.bz.item(a);
        }
        if (this.calloutSeriesSelecting != null) {
            let g = ((() => {
                let $ret = new CalloutSeriesSelectingEventArgs();
                $ret.c = c;
                $ret.d = d;
                $ret.item = this.bz.item(a);
                return $ret;
            })());
            this.calloutSeriesSelecting(this, g);
            if (g.a != null) {
                f.b.series = g.a;
            }
            else if (g.e != null) {
                if (b.containsKey(g.e)) {
                    f.b.series = b.item(g.e);
                }
            }
        }
        this.pq(f);
    }
    pq(a) {
        let b = new Thickness(0, 3);
        if (isNaN_(this.qn.c) || isNaN_(this.qn.e) || isNaN_(this.qn.d) || isNaN_(this.qn.b)) {
            b = new Thickness(0, 3);
        }
        else {
            b = this.qn;
        }
        let c = this.qg != null ? this.qg : this.mw.ce(a.b.series);
        let d = this.qj != null ? this.qj : this.mw.ch();
        let e = this.qi != null ? this.qi : this.mw.cg();
        let f = this.qh != null ? this.qh : this.mw.cf(a.b.series);
        let g = isNaN_(this.n4) ? 0 : this.n4;
        if (this.no && this.calloutStyleUpdating != null) {
            let h = new CalloutStyleUpdatingEventArgs();
            h.item = a.b.content;
            h.xValue = a.b.xValue;
            h.yValue = a.b.yValue;
            h.series = a.b.series;
            h.background = c;
            h.textColor = d;
            h.outline = e;
            h.leaderBrush = f;
            h.strokeThickness = g;
            this.calloutStyleUpdating(this, h);
            c = h.background;
            d = h.textColor;
            e = h.outline;
            f = h.leaderBrush;
            g = h.strokeThickness;
        }
        a.b.backgroundPadding = b;
        a.b.background = c;
        a.b.textColor = d;
        a.b.outline = e;
        a.b.leaderBrush = f;
        a.b.strokeThickness = g;
    }
    get m9() {
        return this.m4;
    }
    set m9(a) {
        if (this.m4 != a) {
            let b = this.m4;
            this.m4 = a;
            this.raisePropertyChanged("LabelColumn", b, this.m4);
        }
    }
    get na() {
        return this.m5;
    }
    set na(a) {
        if (this.m5 != a) {
            let b = this.m5;
            this.m5 = a;
            this.raisePropertyChanged("XColumn", b, this.m5);
        }
    }
    get nb() {
        return this.m6;
    }
    set nb(a) {
        if (this.m6 != a) {
            let b = this.m6;
            this.m6 = a;
            this.raisePropertyChanged("YColumn", b, this.m6);
        }
    }
    get m8() {
        return this.m3;
    }
    set m8(a) {
        if (this.m3 != a) {
            let b = this.m3;
            this.m3 = a;
            this.raisePropertyChanged("KeyColumn", b, this.m3);
        }
    }
    get m7() {
        return this.m2;
    }
    set m7(a) {
        if (this.m2 != a) {
            let b = this.m2;
            this.m2 = a;
            this.raisePropertyChanged("ContentColumn", b, this.m2);
        }
    }
    pf(a, b) {
        if (b.propertyName == CalloutAnnotation.$$p[13] || b.propertyName == CalloutAnnotation.$$p[14]) {
            let c = a.k;
            if (!this.ns.contains(c)) {
                this.nv.add(c);
                this.i4(false);
            }
        }
    }
    bf() {
        return new CalloutLayerView(this);
    }
    il(a) {
        super.il(a);
        this.mw = a;
    }
    get qn() {
        return new Thickness(1, this.n0, this.n2, this.n1, this.nz);
    }
    get m1() {
        if (this.m0 == null) {
            this.m0 = FontUtil.toFontInfo(this.e0, this.o4);
        }
        return this.m0;
    }
    ma(a, b) {
        if (this.mz == null || this.mz == a) {
            if (!this.aq.c) {
                this.i4(b);
            }
        }
    }
    mc(a, b) {
        super.mc(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.nx();
        let e = new List$1(CalloutAnnotationWrapper.$, 0);
        if (this.nm) {
            if (this.lx(this.mz)) {
                this.pm(this.mz, c, e);
            }
            else {
                for (let f of fromEnum(this.bs.series)) {
                    if (this.lx(f)) {
                        this.pm(f, c, e);
                    }
                }
            }
        }
        this.pl(c, d, e);
    }
    jk(a, b) {
        super.jk(a, b);
        let c = b.width - this.ql.width;
        let d = b.height - this.ql.height;
        let e = 0;
        if (Math.abs(c) > Math.abs(d)) {
            e = c;
            this.ny = c * this.lp.width;
        }
        else {
            e = d;
            this.ny = d * this.lp.height;
        }
        if (e > 0 && this.ny > 5) {
            this.nl = true;
        }
        if (e < 0 && this.ny > 5) {
            this.nk = true;
        }
    }
    jj(a, b) {
        super.jj(a, b);
        if (!a.equals1(b)) {
            this.nj = true;
        }
    }
    get qm() {
        return this.qk;
    }
    set qm(a) {
        this.qk = a;
    }
    pl(a, b, c) {
        if (this.bs != null) {
            this.ql = this.bs.mn;
        }
        if (this.lp.isEmpty) {
            return;
        }
        this.qm = new Rect(0, this.lp.left, this.lp.top, this.lp.width, this.lp.height);
        if (this.nc != null && this.op != null && this.op != this.nc.ak) {
            this.ph();
        }
        if (this.nc == null) {
            let d = this.nd();
            if (d != null) {
                this.nc = d;
                let e = this.nc;
                e.labelsMoved = delegateCombine(e.labelsMoved, runOn(this, this.pe));
            }
            else {
                let f = this.lh(this.bi);
                this.nc = new LabelCollisionManager(this.lp.right, this.lp.bottom, this.lp, this.mw.b4(), this.n3, this.ne(), this.oa(), this.n9(), this.nn);
                if (this.op != null) {
                    this.nc.ak = this.op;
                    this.nc.ai = this;
                }
                let g = this.nc;
                g.labelsMoved = delegateCombine(g.labelsMoved, runOn(this, this.pe));
            }
        }
        if (this.nk) {
            this.nk = false;
            if (this.nc.ag > 2) {
                this.ni = true;
            }
        }
        if (this.nl) {
            this.nl = false;
            if (this.ny > 5) {
                this.ni = true;
            }
        }
        if (this.nj) {
            this.nj = false;
            this.nc.ax(this.lp.right, this.lp.bottom, this.lp);
            this.ni = true;
        }
        let h = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        let i = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        let j = new List$1(CalloutAnnotationWrapper.$, 0);
        let k = new List$1(CalloutAnnotationWrapper.$, 0);
        let l = new HashSet$1(CalloutAnnotationWrapper.$, 0);
        for (let m = 0; m < b.count; m++) {
            l.add_1(b._inner[m]);
        }
        for (let n = 0; n < c.count; n++) {
            l.add_1(c._inner[n]);
        }
        let o = this.nt.c;
        while (o != null) {
            let p = o.a;
            if (!l.contains(o.c)) {
                k.add(o.c);
                i.add_1(o.c);
                let q = o.c.b;
                q.propertyChanged = delegateRemove(q.propertyChanged, runOn(this, this.pf));
                this.nt.h(o);
                this.nq.removeItem(o.c);
                this.nc.aw(o.c.c);
            }
            o = p;
        }
        for (let r = 0; r < b.count; r++) {
            if (!this.nq.containsKey(b._inner[r])) {
                this.nt.f(b._inner[r]);
                let s = b._inner[r].b;
                s.propertyChanged = delegateCombine(s.propertyChanged, runOn(this, this.pf));
                this.nq.addItem(b._inner[r], this.nt.d);
                j.add(b._inner[r]);
                h.add_1(b._inner[r]);
                this.ni = true;
            }
        }
        for (let t = 0; t < c.count; t++) {
            if (!this.nq.containsKey(c._inner[t])) {
                this.nt.f(c._inner[t]);
                this.nq.addItem(c._inner[t], this.nt.d);
                let u = c._inner[t].b;
                u.propertyChanged = delegateCombine(u.propertyChanged, runOn(this, this.pf));
                j.add(c._inner[t]);
                h.add_1(c._inner[t]);
                this.ni = true;
            }
        }
        if (this.nv.count > 0) {
            this.ni = true;
            this.nv.clear();
            this.ns.clear();
        }
        o = this.nt.c;
        while (o != null) {
            let v = this.nf(o.c);
            if (v == null) {
                return;
            }
            if (!Base.equalsStatic(v, o.c.c.c)) {
                let w = false;
                if (o.c.c.c == null) {
                    w = true;
                }
                let x = o.c.c;
                x.o = v.b;
                x.p = v.c;
                if (!isNaN_(x.o) && !isNaN_(x.p)) {
                    x.n = v.e;
                    x.m = v.d;
                    if (x.b == null) {
                        this.nc.p(x);
                    }
                    if (w) {
                        this.nc.al(x);
                    }
                    else {
                        this.nc.at(x);
                    }
                }
            }
            o = o.a;
        }
        let y = this.nc.ah();
        let z = this.nc.q();
        if (this.ni && (y != 0 || z)) {
            this.ni = false;
            this.n6 = 0x7FFFFFFF;
            if (this.op != null) {
                let aa = true;
                for (let ab = 0; ab < this.bs.series.count; ab++) {
                    let ac = this.bs.series._inner[ab];
                    if (ac.cj && typeCast(CalloutLayer.$, ac) !== null) {
                        let ad = ac;
                        if (ad.op == this.op) {
                            if (!ad.qm.equals1(this.nc.az)) {
                                aa = false;
                                break;
                            }
                        }
                    }
                }
                if (aa) {
                    this.nc.ay();
                }
                else {
                    this.nc.am();
                }
            }
            else {
                this.nc.ay();
            }
        }
        let ae = this.nt.c;
        while (ae != null) {
            let af = ae.c;
            a.m.add1(af);
            a.f.add(af.b.background);
            a.h.add(af.b.outline);
            a.g.add(af.b.leaderBrush);
            a.j.add(af.b.backgroundPadding.c);
            a.l.add(af.b.backgroundPadding.e);
            a.k.add(af.b.backgroundPadding.d);
            a.i.add(af.b.backgroundPadding.b);
            a.n.add(af.b.strokeThickness);
            a.o.add(af.b.textColor);
            a.p.add1(af.b.text);
            a.q.add1(af.b.content);
            let ag = af.c;
            a.t.add(af.c.o - (af.c.g - af.c.l));
            a.u.add(af.c.p - (af.c.h - af.c.k));
            a.r.add(af.c.g - af.c.l);
            a.s.add(af.c.h - af.c.k);
            ae = ae.a;
        }
    }
    ph() {
        if (this.nc != null) {
            let a = this.nt.c;
            while (a != null) {
                let b = a.c.c;
                if (b != null) {
                    this.nc.aw(b);
                }
                a = a.a;
            }
            let c = this.nc;
            c.labelsMoved = delegateRemove(c.labelsMoved, runOn(this, this.pe));
            this.nc = null;
        }
        this.pg();
    }
    nd() {
        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.op != null && c.op == this.op) {
                        if (c.nc != null) {
                            return c.nc;
                        }
                    }
                }
            }
        }
        return null;
    }
    n9() {
        return 20000;
    }
    oa() {
        return 300;
    }
    ne() {
        switch (this.mt) {
            case 0: return 2;
            case 2: return 1;
            case 3: return 2;
            case 1: return 0;
        }
        return 2;
    }
    pe(a) {
        let b = this.nc.ah();
        if (b < this.n6) {
            this.n6 = b;
            this.i4(false);
        }
    }
    nf(a) {
        let b = this.mz;
        if (a.b.series != null) {
            b = a.b.series;
        }
        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.ed();
        let g = null;
        let h = null;
        for (let i = 0; i < e.length; i++) {
            if (e[i].ce) {
                h = e[i];
            }
            else {
                g = e[i];
            }
        }
        if (g == null || h == null) {
            return null;
        }
        if (!g.cd() || !h.cd()) {
            return null;
        }
        let j = 0;
        if (g.b2 && g.categoryMode != 0) {
            if (b.cr) {
                j = b.getOffsetValue();
            }
            else if (b.cl) {
                j = b.getOffsetValue();
            }
        }
        let k = new ScalerParams(0, this.bs.mn, g.iu, g.b8, g.ip());
        k.b = f;
        let l = new ScalerParams(0, this.bs.mn, h.iu, h.b8, h.ip());
        l.b = f;
        let m = g.dt(this.n5(a.b.xValue), k) + j;
        let n = h.dt(this.n5(a.b.yValue), l);
        let o = new QuadTreeBoundingBox();
        o.b = m;
        o.c = n;
        o.e = 3;
        o.d = 3;
        o.g = a.b;
        return o;
    }
    n5(a) {
        if (typeCast(Date_$type, a) !== null) {
            return a.getTime();
        }
        if (a == null) {
            return 0;
        }
        return a;
    }
    nx() {
        let a = new List$1(CalloutAnnotationWrapper.$, 0);
        for (let b = 0; b < this.nw.count; b++) {
            if (stringIsNullOrEmpty(this.nw._inner[b].b.text)) {
                continue;
            }
            if (this.nw._inner[b].c == null) {
                let c = new LabelCollisionInfo();
                this.nw._inner[b].c = c;
                let d = this.mw.cj(this.ob(this.nw._inner[b]), this.nw._inner[b].b.backgroundPadding);
                c.k = d.height / 2;
                c.l = d.width / 2;
            }
            let e = this.nf(this.nw._inner[b]);
            if (e == null || e.b < this.lp.left || e.b > this.lp.right || e.c < this.lp.top || e.c > this.lp.bottom) {
                continue;
            }
            a.add(this.nw._inner[b]);
        }
        return a;
    }
    ob(a) {
        return a.b.text;
    }
    lx(a) {
        if (!super.lx(a)) {
            return false;
        }
        return true;
    }
    ie() {
        super.ie();
        if (!this.aq.c && !this.ca()) {
            return;
        }
        if (this.ng) {
            this.ng = false;
            this.pj();
        }
        if (this.ca()) {
            this.po(this.lu, false);
        }
        else {
            this.po(this.ls, false);
        }
    }
    pk() {
        if (!this.nh) {
            this.nh = true;
            this.i4(true);
        }
    }
    pm(a, b, c) {
        if (a.ch(this.nu, this.np, this.n7)) {
            let d = this.nu;
            for (let e = 0; e < this.nu.count; e++) {
                let f = d._inner[e];
                let g = f.a.item != null ? f.a.item : f.a;
                let h = a;
                let i = new CalloutKey(g, h);
                let j = new CalloutAnnotationWrapper();
                let k = new CalloutAnnotation();
                j.b = k;
                k.key = i;
                let l = false;
                let m = false;
                if (this.nh) {
                    this.nh = false;
                    m = true;
                }
                if (this.nq.containsKey(j)) {
                    j = this.nq.item(j).c;
                    k = j.b;
                }
                else {
                    if (!m) {
                        l = true;
                    }
                }
                let n = k.xValue;
                let o = k.yValue;
                if (this.n5(n) != this.n5(f.b)) {
                    k.xValue = f.b;
                }
                if (this.n5(o) != this.n5(f.c)) {
                    k.yValue = f.c;
                }
                k.series = a;
                if (l && this.calloutLabelUpdating != null) {
                    let p = ((() => {
                        let $ret = new CalloutLabelUpdatingEventArgs();
                        $ret.c = k.xValue;
                        $ret.d = k.yValue;
                        $ret.item = g;
                        return $ret;
                    })());
                    this.calloutLabelUpdating(this, p);
                    if (p.b != null && !Base.equalsStatic(p.b, j.b.text)) {
                        let q = p.b;
                        j.b.text = q != null ? q.toString() : "";
                    }
                }
                else {
                    if (f.d != null) {
                        k.text = f.d;
                    }
                }
                if (k.text == null) {
                    continue;
                }
                if (l) {
                    if (this.calloutContentUpdating != null) {
                        let r = ((() => {
                            let $ret = new CalloutContentUpdatingEventArgs();
                            $ret.c = k.xValue;
                            $ret.d = k.yValue;
                            $ret.item = g;
                            $ret.a = g;
                            return $ret;
                        })());
                        this.calloutContentUpdating(this, r);
                        if (r.a != null && r.a != j.b.content) {
                            j.b.content = r.a;
                        }
                    }
                    else {
                        if (g != null && g != j.b.content) {
                            j.b.content = g;
                        }
                    }
                }
                if (l) {
                    this.pq(j);
                }
                if (j.c == null) {
                    let s = new LabelCollisionInfo();
                    j.c = s;
                    let t = this.mw.cj(this.ob(j), j.b.backgroundPadding);
                    s.k = t.height / 2;
                    s.l = t.width / 2;
                }
                let u = this.nf(j);
                if (u == null || u.b < this.lp.left || u.b > this.lp.right || u.c < this.lp.top || u.c > this.lp.bottom) {
                    continue;
                }
                c.add(j);
            }
        }
    }
    bd() {
        return 1;
    }
    ar(a, b) {
        let c = this.nc.d(a, b);
        if (c == null) {
            return null;
        }
        return c.u;
    }
    df(a, b) {
        if (this.nc == null) {
            return false;
        }
        return this.nc.d(a, b) != null;
    }
    po(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.mw.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.mw.cc(f, Math.min(a.r._inner[c], a.r._inner[c] + a.t._inner[c]), Math.min(a.s._inner[c], a.s._inner[c] + a.u._inner[c]));
            this.mw.cd(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.mw.b6.c)) {
            if (!d.contains(i)) {
                h.add(i);
            }
        }
        for (let j = 0; j < h.count; j++) {
            this.mw.b6.g(h._inner[j]);
        }
    }
    mf(a, b) {
        super.mf(a, b);
        if (this.ca()) {
            this.po(this.lu, true);
        }
        else {
            this.po(this.ls, false);
        }
    }
    c6() {
        return true;
    }
    ir(a, b, c, d) {
        super.ir(a, b, c, d);
        switch (b) {
            case CalloutLayer.$$p[21]:
                this.m0 = null;
                this.i4(true);
                break;
            case CalloutLayer.$$p[20]:
                this.i4(true);
                break;
            case CalloutLayer.$$p[13]:
                this.i4(true);
                break;
            case "SeriesViewer":
                if (c != null) {
                    let e = c;
                    e.seriesAnimating = delegateRemove(e.seriesAnimating, runOn(this, this.pn));
                }
                if (d != null) {
                    let f = d;
                    f.seriesAnimating = delegateCombine(f.seriesAnimating, runOn(this, this.pn));
                }
                if (d == null) {
                    this.ph();
                }
                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.pi();
                break;
            case CalloutLayer.$$p[19]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.m9);
                    this.m9 = this.by(this.o1);
                }
                break;
            case "LabelColumn":
                this.pi();
                break;
            case CalloutLayer.$$p[14]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.m7);
                    this.m7 = this.by(this.os);
                }
                break;
            case "ContentColumn":
                this.pi();
                break;
            case CalloutLayer.$$p[23]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.na);
                    this.na = stringIsNullOrEmpty(this.o8) == false ? this.by(this.o8) : null;
                }
                break;
            case "XColumn":
                this.pi();
                break;
            case CalloutLayer.$$p[24]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nb);
                    this.nb = this.by(this.pb);
                }
                break;
            case "YColumn":
                this.pi();
                break;
            case CalloutLayer.$$p[18]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.m8);
                    this.m8 = this.by(this.oy);
                }
                break;
            case "KeyColumn":
                this.pi();
                break;
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.m9);
                    c.deregisterColumn(this.m7);
                    c.deregisterColumn(this.na);
                    c.deregisterColumn(this.nb);
                    c.deregisterColumn(this.m8);
                    this.m9 = null;
                    this.m7 = null;
                    this.na = null;
                    this.nb = null;
                    this.m8 = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.m9 = this.by(this.o1);
                    this.m7 = this.by(this.os);
                    if (stringIsNullOrEmpty(this.o8) == false) {
                        this.na = this.by(this.o8);
                    }
                    this.nb = this.by(this.pb);
                    this.m8 = this.by(this.oy);
                }
                this.pi();
                break;
        }
    }
    pn(a) {
        if (a.cj) {
            return;
        }
        if ((a == this.mz || this.mz == null) && this.nm) {
            this.i4(false);
        }
    }
    pi() {
        if (this.ng == false) {
            this.ng = true;
            this.i4(false);
        }
    }
    pg() {
        this.mw.b6.clear();
        this.nt.g();
        this.nq.clear();
    }
    pj() {
        if (this.nb == null || this.m9 == null) {
            let a = this.nt.c;
            while (a != null) {
                this.pq(a.c);
                a = a.a;
            }
            return;
        }
        let b = this.nr();
        for (let c = 0; c < this.nb.count; c++) {
            let d;
            if (this.nw.count <= c) {
                let e = new CalloutAnnotation();
                d = new CalloutAnnotationWrapper();
                d.b = e;
                d.b.series = this.mz;
                this.nw.add(d);
            }
            else {
                d = this.nw._inner[c];
            }
            this.pp(c, b);
        }
    }
}
CalloutLayer.$t = markType(CalloutLayer, 'CalloutLayer', AnnotationLayer.$);
Type.dep(DependencyProperty, PropertyMetadata, CalloutLayer, 'raisePropertyChanged', ['AutoCalloutLabelPrecision:n7:pr', [1, 5], 'CalloutBackground:qg:ps', [Brush.$, null], 'CalloutCollisionMode:mt:pt', [CalloutCollisionMode_$type, enumGetBox(CalloutCollisionMode_$type, 3)], 'CalloutInterpolatedValuePrecision:n8:pu', [1, -1], 'CalloutLeaderBrush:qh:pv', [Brush.$, null], 'CalloutOutline:qi:pw', [Brush.$, null], 'CalloutPaddingBottom:nz:px', [1, NaN], 'CalloutPaddingLeft:n0:py', [1, NaN], 'CalloutPaddingRight:n1:pz', [1, NaN], 'CalloutPaddingTop:n2:p0', [1, NaN], 'CalloutPositionPadding:n3:p1', [1, 10], 'CalloutStrokeThickness:n4:p2', [1, NaN], 'CalloutTextColor:qj:p3', [Brush.$, null], 'CollisionChannel:op:p4', [2, null], 'ContentMemberPath:os:p5', [2, null], 'IsAutoCalloutBehaviorEnabled:nm:p6', [0, false], 'IsCalloutOffsettingEnabled:nn:p7', [0, true], 'IsCustomCalloutStyleEnabled:no:p8', [0, false], 'KeyMemberPath:oy:p9', [2, null], 'LabelMemberPath:o1:qa', [2, null], 'TargetSeries:mz:qb', [Series.$, null], 'TextStyle:o4:qc', [2, null], 'UseValueForAutoCalloutLabels:np:qd', [0, true], 'XMemberPath:o8:qe', [2, null], 'YMemberPath:pb:qf', [2, null]]);
export 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.b9);
            $ret.disactivate = runOn(this, this.cb);
            $ret.destroy = runOn(this, this.ca);
            return $ret;
        })());
    }
    b3() {
        let a = new CalloutView(this);
        this.b7.add(a);
        return a;
    }
    b9(a) {
        a.w = 0;
    }
    cb(a) {
        a.w = 1;
    }
    ca(a) {
        this.b7.remove(a);
    }
    ci(a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.h(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.m1 != null) {
            return this.b1.m1;
        }
        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);
        }
    }
    ck(a) {
        if (isNaN_(this.b8)) {
            this.b8 = this.e.bs.bm.a7;
        }
        return new Size(1, this.h.f(a.ak), this.b8);
    }
    cj(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.bm.i.af);
    }
    cc(a, b, c) {
        a.d = b;
        a.e = c;
    }
    cd(a, b, c) {
        a.i(this.e, b, c);
    }
    ce(a) {
        if (a != null) {
            return this.ci(a.ku);
        }
        return this.e.ku;
    }
    ch() {
        return ((() => {
            let $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    }
    cg() {
        return ((() => {
            let $ret = new Brush();
            $ret.color = Color.u(255, 255, 255, 255);
            return $ret;
        })());
    }
    cf(a) {
        if (a != null) {
            return this.ci(a.ku);
        }
        return this.e.ku;
    }
}
CalloutLayerView.$t = markType(CalloutLayerView, 'CalloutLayerView', AnnotationLayerView.$);
export 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.ck(this.j);
        this.j.m = a.width;
        this.j.l = a.height;
        return new Size(1, a.width + this.u.c + this.u.d, a.height + this.u.e + this.u.b);
    }
    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 = markType(CalloutView, 'CalloutView');
