/*
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 { Brush } from "igniteui-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { Series } from "./Series";
import { Thickness } from "igniteui-angular-core";
import { Visibility_$type } from "igniteui-angular-core";
import { CrosshairLayerFrame } from "./CrosshairLayerFrame";
import { List$1 } from "igniteui-angular-core";
import { Axis } from "./Axis";
import { Dictionary$2 } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { AxisAnnotation } from "./AxisAnnotation";
import { Base, Number_$type, enumGetBox, fromEnum, Point_$type, markType, markDep, runOn } from "igniteui-angular-core";
import { AxisAnnotationFrameManager } from "./AxisAnnotationFrameManager";
import { Tuple$2 } from "igniteui-angular-core";
import { DoubleCollection } from "igniteui-angular-core";
import { DeviceUtils } from "igniteui-angular-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { Path } from "igniteui-angular-core";
import { PathGeometry } from "igniteui-angular-core";
import { PathFigure } from "igniteui-angular-core";
import { LineSegment } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_ } from "igniteui-angular-core";
import { Defaults } from "./Defaults";
import { TranslateTransform } from "igniteui-angular-core";
import { LineGeometry } from "igniteui-angular-core";
/**
 * @hidden
 */
export let CrosshairLayer = /*@__PURE__*/ (() => {
    class CrosshairLayer extends AnnotationLayer {
        constructor() {
            super();
            this.xAxisAnnotationFormatLabel = null;
            this.yAxisAnnotationFormatLabel = null;
            this.ac8 = null;
            this.aar = null;
            this.aaq = null;
            let a = new CrosshairLayerFrame();
            let b = new CrosshairLayerFrame();
            let c = new CrosshairLayerFrame();
            let d = this.kh / 1000;
            this.xm = a;
            this.xl = b;
            this.xn = c;
            this.ab = CrosshairLayer.$;
        }
        bk() {
            return new CrosshairLayer();
        }
        get_et() {
            return true;
        }
        get_er() {
            return true;
        }
        ct() {
            return new CrosshairLayerView(this);
        }
        q7(a) {
            super.q7(a);
            this.aah = a;
        }
        gv(a) {
            if (this.aai == null) {
                return true;
            }
            if (this.aai == a) {
                return true;
            }
            return false;
        }
        aaj() {
            return this.xAxisAnnotationFormatLabel != null;
        }
        aak() {
            return this.yAxisAnnotationFormatLabel != null;
        }
        get ada() {
            return new Thickness(1, this.aau, this.aaw, this.aav, this.aat);
        }
        get adb() {
            return new Thickness(1, this.aa0, this.aa2, this.aa1, this.aaz);
        }
        y1(a, b) {
            if (this.aai == null || this.aai == a) {
                if (!this.a1.c) {
                    this.ry(b);
                }
            }
        }
        y3(a, b) {
            super.y3(a, b);
            let c = a;
            let d = this.aap;
            let e = this.aao;
            c.af.clear();
            c.ag.clear();
            c.ae.clear();
            c.ah.clear();
            AxisAnnotationFrameManager.b(c);
            if (this.xs(this.aai)) {
                this.ab3(this.aai, c, d, e);
            }
            else {
                for (let f of fromEnum(this.dc.series)) {
                    if (this.xs(f)) {
                        this.ab3(f, c, d, e);
                    }
                    if (f.isStacked) {
                        f.p9((g) => {
                            if (this.xs(g)) {
                                this.ab3(g, c, d, e);
                            }
                            if (g.ei) {
                                g.p7((h) => {
                                    if (this.xs(h)) {
                                        this.ab3(h, c, d, e);
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    if (f.ei) {
                        f.p7((g) => {
                            if (this.xs(g)) {
                                this.ab3(g, c, d, e);
                            }
                            return true;
                        });
                    }
                }
            }
        }
        xs(a) {
            if (!super.xs(a)) {
                return false;
            }
            if (this.abc != null) {
                if (a.isFragment) {
                    let b = a.nh();
                    if (!Base.equalsStatic(this.abc, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.abc, a.name)) {
                        return false;
                    }
                }
            }
            let c = this.yw(a);
            if (!c.c) {
                return false;
            }
            return true;
        }
        qv() {
            super.qv();
            if (!this.a1.c && !this.d4()) {
                return;
            }
            if (this.d4()) {
                this.ab4(this.xn, false);
            }
            else {
                this.ab4(this.xl, false);
            }
        }
        xc() {
            return 1;
        }
        xz() {
            return 0.1;
        }
        x2() {
            return -0.4;
        }
        x1() {
            return 0.5;
        }
        z4() {
            return this.w9 == 3 ? this.ac9() : null;
        }
        z5() {
            return this.xa == 3 ? this.ac9() : null;
        }
        ac9() {
            if (this.ac8 == null) {
                this.ac8 = new DoubleCollection();
                this.ac8.add(DeviceUtils.g(5));
                this.ac8.add(DeviceUtils.g(5));
            }
            return this.ac8;
        }
        ab3(a, b, c, d) {
            let e = this.yw(a);
            if (!e.c) {
                return;
            }
            let f = e.d;
            let g = a.i8(f, c, d);
            if (this.aam && isNaN_(g)) {
                return;
            }
            if (this.aan && a.isFragment && g == 0) {
                return;
            }
            f = a.wm(f, c, d);
            let h = false;
            let i = this.vj;
            if (i == null) {
                i = this.vp;
            }
            if (i == null) {
                i = a.vj;
                h = true;
            }
            let j = false;
            let k = this.ac2;
            if (k == null) {
                if (this.vp != null) {
                    k = this.vp;
                }
                else {
                    k = a.vj;
                    j = true;
                }
            }
            let l = false;
            let m = this.ac5;
            if (m == null) {
                if (this.vp != null) {
                    m = this.vp;
                }
                else {
                    m = a.vj;
                    l = true;
                }
            }
            let n = i;
            let o = i;
            let p = k;
            let q = m;
            if (this.ac0 != null) {
                n = this.ac0;
            }
            else if (h) {
                switch (this.w9) {
                    case 0:
                    case 1:
                        n = this.aah.ck(n, this.xw);
                        break;
                    case 2:
                        n = this.aah.cm(n, this.xw);
                        break;
                    case 4:
                        n = this.aah.cl(n, this.xw);
                        break;
                }
            }
            if (this.ac1 != null) {
                o = this.ac1;
            }
            else if (h) {
                switch (this.xa) {
                    case 0:
                    case 1:
                        o = this.aah.ck(o, this.xy);
                        break;
                    case 2:
                        o = this.aah.cm(o, this.xy);
                        break;
                    case 4:
                        o = this.aah.cl(o, this.xy);
                        break;
                }
            }
            if (j) {
                switch (this.xa) {
                    case 1:
                        p = this.aah.ck(p, this.xy);
                        break;
                    case 2:
                        p = this.aah.cm(p, this.xy);
                        break;
                }
            }
            if (l) {
                switch (this.w9) {
                    case 1:
                        q = this.aah.ck(q, this.xw);
                        break;
                    case 2:
                        q = this.aah.cm(q, this.xw);
                        break;
                }
            }
            b.ae.add(n);
            b.ah.add(o);
            b.af.add(f.y);
            b.ag.add(f.x);
            if (this.aal && !isNaN_(f.y)) {
                AxisAnnotationFrameManager.c(b, f, a, this.dc, this.getEffectiveViewport(), i, p, this.aas, this.ac4, this.ac3, this.ada, this.aax, q, this.aay, this.ac7, this.ac6, this.adb, this.aa3, this.add == 0, this.adc == 0);
            }
        }
        ab4(a, b) {
            let c = false;
            if (this.aaq == null) {
                c = true;
                this.aar = new List$1(Axis.$, 0);
                this.aaq = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
            }
            AxisAnnotationFrameManager.d(this, a, c, this.aaq, this.aar, b, this.aa4, this.aa5, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
        }
        ab2(a, b, c, d, e) {
            let f = a.item(b);
            b++;
            if (e) {
                f._stroke = d.ah._inner[c];
                f._fill = d.ah._inner[c];
            }
            else {
                f._stroke = d.ae._inner[c];
                f._fill = d.ae._inner[c];
            }
            f.ad = this.ig;
            f.ai = e ? this.z2 : this.z1;
            f.am = this.wf;
            f.al = this.we;
            f.ak = this.we;
            f.aj = this.wd;
            f.ac = this.jk;
            return new Tuple$2(Path.$, Number_$type, f, b);
        }
        y6(a, b) {
            super.y6(a, b);
            let c = this.aah.co;
            let d = a;
            let e = d.af.count;
            let f = 0;
            let g = b.b9.left;
            let h = b.b9.right;
            let i = b.b9.top;
            let j = b.b9.bottom;
            let k = this.add == 0;
            let l = this.adc == 0;
            for (let m = 0; m < e; m++) {
                let n = Math.floor(d.af._inner[m]);
                let o = Math.floor(d.ag._inner[m]);
                let p = null;
                if (k) {
                    if (isNaN_(n)) {
                        continue;
                    }
                    let q = this.ab2(c, f, m, d, true);
                    p = q.c;
                    f = q.d;
                    let r = new PathGeometry();
                    let s = new PathFigure();
                    s._startPoint = { $type: Point_$type, x: o, y: i };
                    let t = new LineSegment(1);
                    t.c = { $type: Point_$type, x: o, y: j };
                    s._segments.add(t);
                    r.c.add(s);
                    p.an = r;
                }
                if (l) {
                    if (isNaN_(n)) {
                        continue;
                    }
                    let u = this.ab2(c, f, m, d, false);
                    p = u.c;
                    f = u.d;
                    let v = new PathGeometry();
                    let w = new PathFigure();
                    w._startPoint = { $type: Point_$type, x: g, y: n };
                    let x = new LineSegment(1);
                    x.c = { $type: Point_$type, x: h, y: n };
                    w._segments.add(x);
                    v.c.add(w);
                    p.an = v;
                }
            }
            c.count = f;
            if (this.d4()) {
                this.ab4(this.xn, true);
            }
            else {
                this.ab4(this.xl, false);
            }
        }
        gb() {
            return true;
        }
        rg(a, b, c, d) {
            super.rg(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (d == null) {
                        if (this.aaq != null && this.aaq.count > 0) {
                            let e;
                            if (this.d4()) {
                                e = this.xn;
                            }
                            else {
                                e = this.xl;
                            }
                            AxisAnnotationFrameManager.b(e);
                            AxisAnnotationFrameManager.d(this, e, true, this.aaq, this.aar, true, this.aa4, this.aa5, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                        }
                    }
                    break;
                case CrosshairLayer.$$p[1]:
                    this.ry(true);
                    break;
                case CrosshairLayer.$$p[10]:
                    this.ry(true);
                    break;
                case CrosshairLayer.$$p[6]:
                case CrosshairLayer.$$p[7]:
                    this.ry(true);
                    break;
                case CrosshairLayer.$$p[2]:
                case CrosshairLayer.$$p[12]:
                case CrosshairLayer.$$p[11]:
                case CrosshairLayer.$$p[14]:
                case CrosshairLayer.$$p[16]:
                case CrosshairLayer.$$p[18]:
                case CrosshairLayer.$$p[17]:
                case CrosshairLayer.$$p[15]:
                case CrosshairLayer.$$p[19]:
                case CrosshairLayer.$$p[20]:
                case CrosshairLayer.$$p[22]:
                case CrosshairLayer.$$p[24]:
                case CrosshairLayer.$$p[26]:
                case CrosshairLayer.$$p[28]:
                case CrosshairLayer.$$p[27]:
                case CrosshairLayer.$$p[25]:
                case CrosshairLayer.$$p[29]:
                case CrosshairLayer.$$p[30]:
                case CrosshairLayer.$$p[0]:
                case CrosshairLayer.$$p[9]:
                case CrosshairLayer.$$p[8]:
                    this.ry(true);
                    break;
            }
        }
    }
    CrosshairLayer.$t = markType(CrosshairLayer, 'CrosshairLayer', AnnotationLayer.$);
    CrosshairLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CrosshairLayer, 'raisePropertyChanged', ['HorizontalLineStroke:ac0:ab5', [Brush.$, null], 'HorizontalLineVisibility:adc:ab6', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:aal:ab7', [0, false], 'SkipAxisAnnotationOnInvalidData:aam:ab8', [0, false], 'SkipAxisAnnotationOnZeroValueFragments:aan:ab9', [0, false], 'SkipUnknownValues:aao:aca', [0, true], 'TargetSeriesName:abc:acb', [2, null], 'TargetSeries:aai:acc', [Series.$, null], 'UseInterpolation:aap:acd', [0, true], 'VerticalLineStroke:ac1:ace', [Brush.$, null], 'VerticalLineVisibility:add:acf', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:aas:acg', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:ac2:ach', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:aa4:aci', [1, -1], 'XAxisAnnotationOutline:ac3:acj', [Brush.$, null], 'XAxisAnnotationPaddingBottom:aat:ack', [1, NaN], 'XAxisAnnotationPaddingLeft:aau:acl', [1, NaN], 'XAxisAnnotationPaddingRight:aav:acm', [1, NaN], 'XAxisAnnotationPaddingTop:aaw:acn', [1, NaN], 'XAxisAnnotationStrokeThickness:aax:aco', [1, NaN], 'XAxisAnnotationTextColor:ac4:acp', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:aay:acq', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:ac5:acr', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:aa5:acs', [1, -1], 'YAxisAnnotationOutline:ac6:act', [Brush.$, null], 'YAxisAnnotationPaddingBottom:aaz:acu', [1, NaN], 'YAxisAnnotationPaddingLeft:aa0:acv', [1, NaN], 'YAxisAnnotationPaddingRight:aa1:acw', [1, NaN], 'YAxisAnnotationPaddingTop:aa2:acx', [1, NaN], 'YAxisAnnotationStrokeThickness:aa3:acy', [1, NaN], 'YAxisAnnotationTextColor:ac7:acz', [Brush.$, null]]);
    return CrosshairLayer;
})();
/**
 * @hidden
 */
export let CrosshairLayerView = /*@__PURE__*/ (() => {
    class CrosshairLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            this.cn = null;
            this.co = null;
            this.cp = null;
            this.cn = a;
            this.cp = new List$1(Path.$, 0);
        }
        a4() {
            super.a4();
            this.co = ((() => {
                let $ret = new Pool$1(Path.$);
                $ret.create = runOn(this, this.cu);
                $ret.activate = runOn(this, this.cq);
                $ret.disactivate = runOn(this, this.cs);
                $ret.destroy = runOn(this, this.cr);
                return $ret;
            })());
            this.cn.jt = Defaults.crosshairLineThickness;
        }
        cu() {
            let a = new Path();
            a.j = new TranslateTransform();
            this.cp.add(a);
            return a;
        }
        cq(a) {
            a._visibility = 0;
        }
        cs(a) {
            a._visibility = 1;
        }
        cr(a) {
            this.cp.remove(a);
        }
        ct(a, b, c, d) {
            if (a.an == null || a.an.c.x != d || a.an.d.x != c) {
                let e = ((() => {
                    let $ret = new LineGeometry();
                    $ret.d = { $type: Point_$type, x: c, y: b };
                    $ret.c = { $type: Point_$type, x: d, y: b };
                    return $ret;
                })());
                a.an = e;
            }
        }
        bj(a, b) {
            super.bj(a, b);
            if (a.d && !b) {
                for (let c = 0; c < this.cp.count; c++) {
                    let d = this.cp._inner[c];
                    if (d._visibility == 0) {
                        a.t(d);
                    }
                }
            }
        }
        ax(a) {
            super.ax(a);
            for (let b = 0; b < this.cp.count; b++) {
                this.f.bc.exportPathData(a, this.cp._inner[b], "crosshairLine", ["Main", "Crosshair"]);
            }
        }
    }
    CrosshairLayerView.$t = markType(CrosshairLayerView, 'CrosshairLayerView', AnnotationLayerView.$);
    return CrosshairLayerView;
})();
