/*
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, Point_$type, Date_$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 { ViewportUtils } from "./ViewportUtils";
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 { 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.po = null;
            this.pp = null;
            this.pq = null;
            this.pn = null;
            this.pm = null;
            this.qd = new HashSet$1(CalloutAnnotationWrapper.$, 0);
            this.qg = new List$1(CalloutAnnotationWrapper.$, 0);
            this.qh = new List$1(CalloutAnnotationWrapper.$, 0);
            this.pk = null;
            this.qe = new LinkedList$1(CalloutAnnotationWrapper.$);
            this.qb = new Dictionary$2(CalloutAnnotationWrapper.$, LinkedListNode$1.$.specialize(CalloutAnnotationWrapper.$), 0);
            this.pw = null;
            this.s9 = new Rect(0, 0, 0, 1, 1);
            this.p3 = false;
            this.qr = 0;
            this.s8 = Rect.empty;
            this.p1 = false;
            this.p2 = false;
            this.calloutContentUpdating = null;
            this.calloutLabelUpdating = null;
            this.calloutSeriesSelecting = null;
            this.qf = new List$1(SeriesPointOfInterest.$, 0);
            this.p5 = false;
            this.p6 = false;
            this.qj = 0;
            this.p4 = false;
            this.p0 = true;
            FastItemObjectColumn.m();
            this.oj = true;
            let a = new CalloutLayerFrame();
            let b = new CalloutLayerFrame();
            let c = new CalloutLayerFrame();
            let d = this.gj / 1000;
            this.ob = a;
            this.oa = b;
            this.oc = c;
            this.ab = CalloutLayer.$;
        }
        r0(a, b) {
            this.qh.clear();
            this.k3(false);
        }
        jo(a, b, c, d) {
            super.jo(a, b, c, d);
            let e = this.qc();
            switch (a) {
                case 3:
                    this.sc(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.pj;
                        this.qh.insert(f, h);
                        this.sc(f, e);
                    }
                    break;
                case 0:
                    this.qh.v(b, c);
                    break;
                case 2:
                    for (let i = b; i < b + c; i++) {
                        this.sc(i, e);
                    }
                    break;
                case 4:
                    this.qh.clear();
                    for (let j = 0; j < this.cd.count; j++) {
                        let k = new CalloutAnnotation();
                        let l = new CalloutAnnotationWrapper();
                        l.b = k;
                        l.b.series = this.pj;
                        this.qh.add(l);
                        this.sc(j, e);
                    }
                    break;
            }
            this.k3(true);
        }
        dr(a) {
            return false;
        }
        qc() {
            let a = new Dictionary$2(String_$type, Series.$, 0);
            if (this.b6 != null) {
                for (let b = 0; b < this.b6.series.count; b++) {
                    let c = this.b6.series._inner[b];
                    if (c.name != null && !a.containsKey(c.name)) {
                        a.addItem(c.name, c);
                    }
                }
            }
            return a;
        }
        sc(a, b) {
            if (this.pv == null || this.pt == null) {
                return;
            }
            let c = a;
            if (this.pu != null) {
                c = this.pu.item(a);
            }
            let d = this.pv.item(a);
            let e = this.pt.item(a);
            let f = this.qh._inner[a];
            if (this.ps != null) {
                if (f.b.aa != this.ps.item(a)) {
                    f.b.key = this.ps.item(a);
                }
            }
            if (this.qb.containsKey(f)) {
                f.b = this.qb.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.cd.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.pr != null) {
                f.b.content = this.pr.item(a);
            }
            else {
                f.b.content = this.cd.item(a);
            }
            if (this.calloutSeriesSelecting != null) {
                let i = ((() => {
                    let $ret = new CalloutSeriesSelectingEventArgs();
                    $ret.c = c;
                    $ret.d = d;
                    $ret.item = this.cd.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.sd(f);
        }
        sd(a) {
            let b = new Thickness(0, 3);
            if (isNaN_(this.tb.c) || isNaN_(this.tb.e) || isNaN_(this.tb.d) || isNaN_(this.tb.b)) {
                b = new Thickness(0, 3);
            }
            else {
                b = this.tb;
            }
            let c = this.s4 != null ? this.s4 : this.pg.ci(a.b.l);
            let d = this.s7 != null ? this.s7 : this.pg.cl();
            let e = this.s6 != null ? this.s6 : this.pg.ck();
            let f = this.s5 != null ? this.s5 : this.pg.cj(a.b.l);
            let g = isNaN_(this.qp) ? 0 : this.qp;
            if (this.p9 && 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;
        }
        gt(a, b) {
            let c = this.ic(b);
            if (c == CalloutLayer.$$p[19]) {
                return this.gu(a, b, this.rm);
            }
            if (c == CalloutLayer.$$p[24]) {
                return this.gu(a, b, this.rv);
            }
            if (c == CalloutLayer.$$p[25]) {
                return this.gu(a, b, this.ry);
            }
            if (c == CalloutLayer.$$p[18]) {
                return this.gu(a, b, this.rj);
            }
            if (c == CalloutLayer.$$p[14]) {
                return this.gu(a, b, this.rd);
            }
            return super.gt(a, b);
        }
        get pt() {
            return this.po;
        }
        set pt(a) {
            if (this.po != a) {
                let b = this.po;
                this.po = a;
                this.raisePropertyChanged("LabelColumn", b, this.po);
            }
        }
        get pu() {
            return this.pp;
        }
        set pu(a) {
            if (this.pp != a) {
                let b = this.pp;
                this.pp = a;
                this.raisePropertyChanged("XColumn", b, this.pp);
            }
        }
        get pv() {
            return this.pq;
        }
        set pv(a) {
            if (this.pq != a) {
                let b = this.pq;
                this.pq = a;
                this.raisePropertyChanged("YColumn", b, this.pq);
            }
        }
        get ps() {
            return this.pn;
        }
        set ps(a) {
            if (this.pn != a) {
                let b = this.pn;
                this.pn = a;
                this.raisePropertyChanged("KeyColumn", b, this.pn);
            }
        }
        get pr() {
            return this.pm;
        }
        set pr(a) {
            if (this.pm != a) {
                let b = this.pm;
                this.pm = a;
                this.raisePropertyChanged("ContentColumn", b, this.pm);
            }
        }
        r2(a, b) {
            if (b.propertyName == CalloutAnnotation.$$p[13] || b.propertyName == CalloutAnnotation.$$p[14]) {
                let c = a.k;
                if (!this.qd.contains(c)) {
                    this.qd.add_1(c);
                    this.qg.add(c);
                    this.k3(false);
                }
            }
        }
        bp() {
            return new CalloutLayerView(this);
        }
        kk(a) {
            super.kk(a);
            this.pg = a;
        }
        get tb() {
            return new Thickness(1, this.ql, this.qn, this.qm, this.qk);
        }
        get pl() {
            if (this.pk == null) {
                this.pk = FontUtil.toFontInfo(this.f5, this.rr);
            }
            return this.pk;
        }
        ou(a, b) {
            if (this.pj == null || this.pj == a) {
                if (!this.ar.c) {
                    this.k3(b);
                }
            }
        }
        ow(a, b) {
            super.ow(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.qi();
            let e = new List$1(CalloutAnnotationWrapper.$, 0);
            if (this.p7) {
                if (this.oh(this.pj)) {
                    this.r9(this.pj, c, e);
                }
                else {
                    for (let f of fromEnum(this.b6.series)) {
                        if (this.oh(f)) {
                            this.r9(f, c, e);
                        }
                    }
                }
            }
            this.r8(c, d, e);
        }
        lo(a, b) {
            super.lo(a, b);
            let c = b.width - this.s9.width;
            let d = b.height - this.s9.height;
            let e = 0;
            if (Math.abs(c) > Math.abs(d)) {
                e = c;
                this.qj = c * this.n6.width;
            }
            else {
                e = d;
                this.qj = d * this.n6.height;
            }
            if (e > 0 && this.qj > 5) {
                this.p6 = true;
            }
            if (e < 0 && this.qj > 5) {
                this.p5 = true;
            }
        }
        ln(a, b) {
            super.ln(a, b);
            if (!a.equals1(b)) {
                this.p4 = true;
            }
        }
        get ta() {
            return this.s8;
        }
        set ta(a) {
            this.s8 = a;
        }
        r8(a, b, c) {
            if (this.b6 != null) {
                this.s9 = this.b6.os;
            }
            if (this.n6.isEmpty) {
                return;
            }
            this.ta = new Rect(0, this.n6.left, this.n6.top, this.n6.width, this.n6.height);
            if (this.pw != null && this.ra != null && this.ra != this.pw.ak) {
                this.r4();
            }
            if (this.pw == null) {
                let d = this.px();
                if (d != null) {
                    this.pw = d;
                    let e = this.pw;
                    e.labelsMoved = delegateCombine(e.labelsMoved, runOn(this, this.r1));
                }
                else {
                    let f = this.ny(this.bs);
                    let g = 0;
                    if (this.pj != null) {
                        if (this.pj.isVertical) {
                            g = 2;
                        }
                    }
                    else {
                        let h = false;
                        if (this.b6 != null && this.b6.series.count > 0) {
                            h = true;
                            for (let i of fromEnum(this.b6.series)) {
                                if (!i.cx) {
                                    if (!i.isVertical) {
                                        h = false;
                                    }
                                }
                            }
                        }
                        if (h) {
                            g = 2;
                        }
                    }
                    this.pw = new LabelCollisionManager(this.n6.right, this.n6.bottom, this.n6, this.pg.j(), this.qo, this.py(), g, this.qv(), this.qu(), this.p8);
                    if (this.ra != null) {
                        this.pw.ak = this.ra;
                        this.pw.ai = this;
                    }
                    let j = this.pw;
                    j.labelsMoved = delegateCombine(j.labelsMoved, runOn(this, this.r1));
                }
            }
            if (this.p5) {
                this.p5 = false;
                if (this.pw.ag > 2) {
                    this.p3 = true;
                }
            }
            if (this.p6) {
                this.p6 = false;
                if (this.qj > 5) {
                    this.p3 = true;
                }
            }
            if (this.p4) {
                this.p4 = false;
                this.pw.ay(this.n6.right, this.n6.bottom, this.n6);
                this.p3 = 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.qe.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.r2));
                    this.qe.h(r);
                    this.qb.removeItem(r.c);
                    this.pw.ax(r.c.c);
                }
                r = s;
            }
            for (let u = 0; u < b.count; u++) {
                if (!this.qb.containsKey(b._inner[u])) {
                    this.qe.f(b._inner[u]);
                    let v = b._inner[u].b;
                    v.propertyChanged = delegateCombine(v.propertyChanged, runOn(this, this.r2));
                    this.qb.addItem(b._inner[u], this.qe.d);
                    m.add(b._inner[u]);
                    k.add_1(b._inner[u]);
                    this.p3 = true;
                }
            }
            for (let w = 0; w < c.count; w++) {
                if (!this.qb.containsKey(c._inner[w])) {
                    this.qe.f(c._inner[w]);
                    this.qb.addItem(c._inner[w], this.qe.d);
                    let x = c._inner[w].b;
                    x.propertyChanged = delegateCombine(x.propertyChanged, runOn(this, this.r2));
                    m.add(c._inner[w]);
                    k.add_1(c._inner[w]);
                    this.p3 = true;
                }
            }
            if (this.p1 == true) {
                this.p1 = false;
                this.p3 = true;
            }
            if (this.qg.count > 0) {
                this.p3 = true;
                this.qg.clear();
                this.qd.clear();
            }
            r = this.qe.c;
            while (r != null) {
                let y = this.pz(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.pw.p(aa);
                        }
                        if (z) {
                            this.pw.al(aa);
                        }
                        else {
                            this.pw.au(aa);
                        }
                    }
                }
                r = r.a;
            }
            let ab = this.pw.ah();
            let ac = this.pw.q();
            if (this.p3 && (ab != 0 || ac)) {
                this.p3 = false;
                this.qr = 0x7FFFFFFF;
                if (this.ra != null) {
                    let ad = true;
                    for (let ae = 0; ae < this.b6.series.count; ae++) {
                        let af = this.b6.series._inner[ae];
                        if (af.cx && typeCast(CalloutLayer.$, af) !== null) {
                            let ag = af;
                            if (ag.ra == this.ra) {
                                if (!ag.ta.equals1(this.pw.a0)) {
                                    ad = false;
                                    break;
                                }
                            }
                        }
                    }
                    if (ad) {
                        this.pw.az();
                    }
                    else {
                        this.pw.am();
                        this.pw.an();
                    }
                }
                else {
                    this.pw.az();
                }
            }
            else {
                this.pw.an();
            }
            let ah = this.qe.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;
            }
        }
        r4() {
            if (this.pw != null) {
                let a = this.qe.c;
                while (a != null) {
                    let b = a.c.c;
                    if (b != null) {
                        this.pw.ax(b);
                    }
                    a = a.a;
                }
                let c = this.pw;
                c.labelsMoved = delegateRemove(c.labelsMoved, runOn(this, this.r1));
                this.pw = null;
            }
            this.r3();
        }
        px() {
            if (this.b6 == null) {
                return null;
            }
            for (let a = 0; a < this.b6.series.count; a++) {
                let b = this.b6.series._inner[a];
                if (b.cx && typeCast(CalloutLayer.$, b) !== null) {
                    let c = b;
                    if (c != this) {
                        if (c.ra != null && c.ra == this.ra) {
                            if (c.pw != null) {
                                return c.pw;
                            }
                        }
                    }
                }
            }
            return null;
        }
        qu() {
            return 20000;
        }
        qv() {
            return 300;
        }
        py() {
            switch (this.pd) {
                case 0: return 2;
                case 2: return 1;
                case 3: return 2;
                case 1: return 0;
            }
            return 2;
        }
        r1(a) {
            let b = this.pw.ah();
            if (b < this.qr) {
                this.qr = b;
                this.k3(false);
            }
        }
        pz(a) {
            let b = this.pj;
            if (a.b.l != null) {
                b = a.b.l;
            }
            if (b == null) {
                for (let c = 0; c < this.b6.series.count; c++) {
                    let d = this.b6.series._inner[c];
                    if (!d.cx) {
                        b = d;
                        break;
                    }
                }
            }
            if (b == null) {
                return null;
            }
            let e = b.ag();
            let f = b.fa();
            let g = null;
            let h = null;
            let i = false;
            for (let j = 0; j < e.length; j++) {
                if (e[j].b2) {
                    i = true;
                    g = e[j];
                }
                else if (e[j].ce) {
                    i = true;
                    h = e[j];
                }
                else if (e[j].ch) {
                    h = e[j];
                }
                else {
                    g = e[j];
                }
            }
            if (g == null || h == null) {
                return null;
            }
            if (!g.cg() || !h.cg()) {
                return null;
            }
            let k = 0;
            let l = 0;
            if (g.b4 && g.categoryMode != 0) {
                if (b.c6) {
                    k = b.getOffsetValue();
                }
                else if (b.cz) {
                    k = b.getOffsetValue();
                }
            }
            if (h.b4 && h.categoryMode != 0) {
                if (b.cz) {
                    l = b.getOffsetValue();
                }
            }
            let m = new ScalerParams(0, this.b6.os, g.ja, g.ca, g.i5());
            m.b = f;
            let n = new ScalerParams(0, this.b6.os, h.ja, h.ca, h.i5());
            n.b = f;
            let o = 0;
            let p = 0;
            if (i) {
                o = g.dz(this.qq(a.b.ab), m) + k;
                p = h.dz(this.qq(a.b.ac), n) + l;
                let q = o;
                let r = p;
                let s = { $type: Point_$type, x: 0.5, y: 0.5 };
                let t = s.x + (r * Math.cos(q));
                o = ViewportUtils.c(t, m.e, m.d);
                let u = s.y + (r * Math.sin(q));
                p = ViewportUtils.f(u, n.e, n.d);
            }
            else {
                o = g.dz(this.qq(a.b.ab), m) + k;
                p = h.dz(this.qq(a.b.ac), n) + l;
            }
            let v = new QuadTreeBoundingBox();
            v.b = o;
            v.c = p;
            v.e = 3;
            v.d = 3;
            v.g = a.b;
            return v;
        }
        qq(a) {
            if (typeCast(Date_$type, a) !== null) {
                return a.getTime();
            }
            if (a == null) {
                return 0;
            }
            return a;
        }
        qi() {
            let a = new List$1(CalloutAnnotationWrapper.$, 0);
            for (let b = 0; b < this.qh.count; b++) {
                if (stringIsNullOrEmpty(this.qh._inner[b].b.am)) {
                    continue;
                }
                if (this.qh._inner[b].c == null) {
                    let c = new LabelCollisionInfo();
                    this.qh._inner[b].c = c;
                    let d = this.pg.cn(this.qw(this.qh._inner[b]), this.qh._inner[b].b.backgroundPadding);
                    c.k = d.height / 2;
                    c.l = d.width / 2;
                }
                let e = this.pz(this.qh._inner[b]);
                if (e == null || e.b < this.n6.left || e.b > this.n6.right || e.c < this.n6.top || e.c > this.n6.bottom) {
                    continue;
                }
                a.add(this.qh._inner[b]);
            }
            return a;
        }
        qw(a) {
            return a.b.am;
        }
        oh(a) {
            if (!super.oh(a)) {
                return false;
            }
            if (this.ro != null) {
                if (a.c7) {
                    let b = a.ib();
                    if (!Base.equalsStatic(this.ro, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.ro, a.name)) {
                        return false;
                    }
                }
            }
            return true;
        }
        kd() {
            super.kd();
            if (!this.ar.c && !this.cn()) {
                return;
            }
            if (this.p0) {
                this.p0 = false;
                this.r6();
            }
            if (this.cn()) {
                this.sb(this.oc, false);
            }
            else {
                this.sb(this.oa, false);
            }
        }
        r7() {
            if (!this.p2) {
                this.p2 = true;
                this.k3(true);
            }
        }
        r9(a, b, c) {
            let d = false;
            if (this.p2) {
                this.p2 = false;
                d = true;
            }
            if (a.ct(this.qf, this.qa, this.qs)) {
                let e = this.qf;
                for (let f = 0; f < this.qf.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.qb.containsKey(k)) {
                        k = this.qb.item(k).c;
                        l = k.b;
                        m = d;
                    }
                    else {
                        m = true;
                    }
                    let n = l.ab;
                    let o = l.ac;
                    if (this.qq(n) != this.qq(g.b)) {
                        l.xValue = g.b;
                    }
                    if (this.qq(o) != this.qq(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.sd(k);
                    }
                    if (k.c == null) {
                        let t = new LabelCollisionInfo();
                        k.c = t;
                        let u = this.pg.cn(this.qw(k), k.b.backgroundPadding);
                        t.k = u.height / 2;
                        t.l = u.width / 2;
                    }
                    let v = this.pz(k);
                    if (v == null || v.b < this.n6.left || v.b > this.n6.right || v.c < this.n6.top || v.c > this.n6.bottom) {
                        continue;
                    }
                    c.add(k);
                }
            }
        }
        bj() {
            return 1;
        }
        as(a, b) {
            let c = this.pw.d(a, b);
            if (c == null) {
                return null;
            }
            return c.u;
        }
        dy(a, b) {
            if (this.pw == null) {
                return false;
            }
            return this.pw.d(a, b) != null;
        }
        sb(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.pg.b8.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.bs.bq();
                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.pg.cg(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.pg.ch(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.pg.b8.c)) {
                if (!d.contains(i)) {
                    h.add(i);
                }
            }
            for (let j = 0; j < h.count; j++) {
                this.pg.b8.h(h._inner[j]);
            }
        }
        oz(a, b) {
            super.oz(a, b);
            if (this.cn()) {
                this.sb(this.oc, true);
            }
            else {
                this.sb(this.oa, false);
            }
        }
        dp() {
            return true;
        }
        kp(a, b, c, d) {
            super.kp(a, b, c, d);
            switch (b) {
                case CalloutLayer.$$p[22]:
                    this.pk = null;
                    this.pg.cf();
                    this.k3(true);
                    break;
                case CalloutLayer.$$p[20]:
                case CalloutLayer.$$p[21]:
                    this.k3(true);
                    break;
                case CalloutLayer.$$p[13]:
                    this.k3(true);
                    break;
                case "SeriesViewer":
                    if (c != null) {
                        let e = c;
                        e.seriesAnimating = delegateRemove(e.seriesAnimating, runOn(this, this.sa));
                    }
                    if (d != null) {
                        let f = d;
                        f.seriesAnimating = delegateCombine(f.seriesAnimating, runOn(this, this.sa));
                    }
                    if (d == null) {
                        this.r4();
                    }
                    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.r5();
                    break;
                case CalloutLayer.$$p[19]:
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.pt);
                        this.pt = this.cc(this.rm);
                    }
                    break;
                case "LabelColumn":
                    this.r5();
                    break;
                case CalloutLayer.$$p[14]:
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.pr);
                        this.pr = this.cc(this.rd);
                    }
                    break;
                case "ContentColumn":
                    this.r5();
                    break;
                case CalloutLayer.$$p[24]:
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.pu);
                        this.pu = stringIsNullOrEmpty(this.rv) == false ? this.cc(this.rv) : null;
                    }
                    break;
                case "XColumn":
                    this.r5();
                    break;
                case CalloutLayer.$$p[25]:
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.pv);
                        this.pv = this.cc(this.ry);
                    }
                    break;
                case "YColumn":
                    this.r5();
                    break;
                case CalloutLayer.$$p[18]:
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.ps);
                        this.ps = this.cc(this.rj);
                    }
                    break;
                case "KeyColumn":
                    this.r5();
                    break;
                case "FastItemsSource":
                    this.p1 = true;
                    if (typeCast(IFastItemsSource_$type, c) != null) {
                        c.deregisterColumn(this.pt);
                        c.deregisterColumn(this.pr);
                        c.deregisterColumn(this.pu);
                        c.deregisterColumn(this.pv);
                        c.deregisterColumn(this.ps);
                        this.pt = null;
                        this.pr = null;
                        this.pu = null;
                        this.pv = null;
                        this.ps = null;
                        this.qh.clear();
                    }
                    if (typeCast(IFastItemsSource_$type, d) != null) {
                        this.pt = this.cc(this.rm);
                        this.pr = this.cc(this.rd);
                        if (stringIsNullOrEmpty(this.rv) == false) {
                            this.pu = this.cc(this.rv);
                        }
                        this.pv = this.cc(this.ry);
                        this.ps = this.cc(this.rj);
                    }
                    this.r5();
                    break;
            }
        }
        sa(a) {
            if (a.cx) {
                return;
            }
            if ((a == this.pj || this.pj == null) && this.p7) {
                this.k3(false);
            }
        }
        r5() {
            if (this.p0 == false) {
                this.p0 = true;
                this.k3(false);
            }
        }
        r3() {
            this.pg.b8.clear();
            this.qe.g();
            this.qb.clear();
        }
        r6() {
            if (this.pv == null || this.pt == null) {
                let a = this.qe.c;
                while (a != null) {
                    this.sd(a.c);
                    a = a.a;
                }
                return;
            }
            let b = this.qc();
            for (let c = 0; c < this.pv.count; c++) {
                let d;
                if (this.qh.count <= c) {
                    let e = new CalloutAnnotation();
                    d = new CalloutAnnotationWrapper();
                    d.b = e;
                    d.b.series = this.pj;
                    this.qh.add(d);
                }
                else {
                    d = this.qh._inner[c];
                }
                this.sc(c, b);
            }
        }
    }
    CalloutLayer.$t = /*@__PURE__*/ markType(CalloutLayer, 'CalloutLayer', AnnotationLayer.$);
    CalloutLayer.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CalloutLayer, 'raisePropertyChanged', ['AutoCalloutLabelPrecision:qs:se', [1, 5], 'CalloutBackground:s4:sf', [Brush.$, null], 'CalloutCollisionMode:pd:sg', [CalloutCollisionMode_$type, /*@__PURE__*/ enumGetBox(CalloutCollisionMode_$type, 3)], 'CalloutInterpolatedValuePrecision:qt:sh', [1, -1], 'CalloutLeaderBrush:s5:si', [Brush.$, null], 'CalloutOutline:s6:sj', [Brush.$, null], 'CalloutPaddingBottom:qk:sk', [1, NaN], 'CalloutPaddingLeft:ql:sl', [1, NaN], 'CalloutPaddingRight:qm:sm', [1, NaN], 'CalloutPaddingTop:qn:sn', [1, NaN], 'CalloutPositionPadding:qo:so', [1, 10], 'CalloutStrokeThickness:qp:sp', [1, NaN], 'CalloutTextColor:s7:sq', [Brush.$, null], 'CollisionChannel:ra:sr', [2, null], 'ContentMemberPath:rd:ss', [2, null], 'IsAutoCalloutBehaviorEnabled:p7:st', [0, false], 'IsCalloutOffsettingEnabled:p8:su', [0, true], 'IsCustomCalloutStyleEnabled:p9:sv', [0, false], 'KeyMemberPath:rj:sw', [2, null], 'LabelMemberPath:rm:sx', [2, null], 'TargetSeriesName:ro:sy', [2, null], 'TargetSeries:pj:sz', [Series.$, null], 'TextStyle:rr:s0', [2, null], 'UseValueForAutoCalloutLabels:qa:s1', [0, true], 'XMemberPath:rv:s2', [2, null], 'YMemberPath:ry:s3', [2, null]]);
    return CalloutLayer;
})();
/**
 * @hidden
 */
export let CalloutLayerView = /*@__PURE__*/ (() => {
    class CalloutLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            this.b4 = null;
            this.b9 = null;
            this.b8 = null;
            this.ca = NaN;
            this.b5 = null;
            this.b4 = a;
            this.b9 = new List$1(CalloutView.$, 0);
        }
        as() {
            super.as();
            this.b8 = ((() => {
                let $ret = new HashPool$2(CalloutAnnotationWrapper.$, CalloutView.$);
                $ret.create = runOn(this, this.b6);
                $ret.activate = runOn(this, this.cc);
                $ret.disactivate = runOn(this, this.ce);
                $ret.destroy = runOn(this, this.cd);
                return $ret;
            })());
        }
        b6() {
            let a = new CalloutView(this);
            this.b9.add(a);
            return a;
        }
        cc(a) {
            a.w = 0;
        }
        ce(a) {
            a.w = 1;
        }
        cd(a) {
            this.b9.remove(a);
        }
        cm(a) {
            if (a == null) {
                return a;
            }
            return BrushUtil.l(a, 0.1);
        }
        a6(a, b) {
            super.a6(a, b);
            a.ac(this.b7());
            if (a.d && !b) {
                for (let c = 0; c < this.b9.count; c++) {
                    let d = this.b9._inner[c];
                    if (d.w == 0) {
                        d.h(a);
                    }
                }
            }
        }
        b7() {
            if (this.b4.pl != null) {
                return this.b4.pl;
            }
            return this.e.b6.getFontInfo();
        }
        al(a) {
            super.al(a);
            for (let b = 0; b < this.b9.count; b++) {
                let c = this.b9._inner[b];
                if (c.w != 0) {
                    continue;
                }
                c.g(this.b4, this.b7(), a);
            }
        }
        co(a) {
            this.k.ac(this.b7());
            this.ca = this.cb();
            return new Size(1, this.k.f(a.ak), this.ca);
        }
        cb() {
            let a = this.b7();
            if (isNaN_(this.ca)) {
                let b = FontUtil.getCurrentFontHeight(this.e.b6.b8.j.ae, a);
                this.ca = b;
            }
            return this.ca;
        }
        cn(a, b) {
            if (this.b5 == null) {
                this.b5 = new CalloutView(this);
            }
            this.b5.f = a;
            this.b5.v = b;
            let c = this.b5.s();
            this.b5.f = null;
            return c;
        }
        cg(a, b, c) {
            a.d = b;
            a.e = c;
        }
        ch(a, b, c) {
            a.i(this.e, b, c);
        }
        ci(a) {
            if (a != null) {
                return this.cm(a.nc);
            }
            return this.e.nc;
        }
        cl() {
            return ((() => {
                let $ret = new Brush();
                $ret.color = Color.u(255, 255, 255, 255);
                return $ret;
            })());
        }
        ck() {
            return ((() => {
                let $ret = new Brush();
                $ret.color = Color.u(255, 255, 255, 255);
                return $ret;
            })());
        }
        cj(a) {
            if (a != null) {
                return this.cm(a.m9);
            }
            return this.e.m9;
        }
        cf() {
            this.ca = 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.co(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.a5.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
