/*
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-react-core";
import { DependencyProperty } from "igniteui-react-core";
import { Series } from "./Series";
import { Thickness } from "igniteui-react-core";
import { Visibility_$type } from "igniteui-react-core";
import { CrosshairLayerFrame } from "./CrosshairLayerFrame";
import { List$1 } from "igniteui-react-core";
import { Axis } from "./Axis";
import { Dictionary$2 } from "igniteui-react-core";
import { Pool$1 } from "igniteui-react-core";
import { AxisAnnotation } from "./AxisAnnotation";
import { Base, Number_$type, enumGetBox, fromEnum, Point_$type, markType, markDep, runOn } from "igniteui-react-core";
import { AxisAnnotationFrameManager } from "./AxisAnnotationFrameManager";
import { Tuple$2 } from "igniteui-react-core";
import { DoubleCollection } from "igniteui-react-core";
import { DeviceUtils } from "igniteui-react-core";
import { Path } from "igniteui-react-core";
import { PathGeometry } from "igniteui-react-core";
import { PathFigure } from "igniteui-react-core";
import { LineSegment } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { isNaN_, truncate } from "igniteui-react-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { Defaults } from "./Defaults";
import { TranslateTransform } from "igniteui-react-core";
import { LineGeometry } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { Color } from "igniteui-react-core";
/**
 * @hidden
 */
export let CrosshairLayer = /*@__PURE__*/ (() => {
    class CrosshairLayer extends AnnotationLayer {
        get_d5() {
            return true;
        }
        get_d3() {
            return true;
        }
        constructor() {
            super();
            this.xAxisAnnotationFormatLabel = null;
            this.yAxisAnnotationFormatLabel = null;
            this.zn = null;
            this.xa = null;
            this.w9 = null;
            let a = new CrosshairLayerFrame();
            let b = new CrosshairLayerFrame();
            let c = new CrosshairLayerFrame();
            let d = this.ji / 1000;
            this.uf = a;
            this.ue = b;
            this.ug = c;
            this.ab = CrosshairLayer.$;
        }
        cg() {
            return new CrosshairLayerView(this);
        }
        o0(a) {
            super.o0(a);
            this.w2 = a;
        }
        w4() {
            return this.xAxisAnnotationFormatLabel != null;
        }
        w5() {
            return this.yAxisAnnotationFormatLabel != null;
        }
        get zp() {
            return new Thickness(1, this.xd, this.xf, this.xe, this.xc);
        }
        get zq() {
            return new Thickness(1, this.xj, this.xl, this.xk, this.xi);
        }
        vs(a, b) {
            if (this.w3 == null || this.w3 == a) {
                if (!this.at.c) {
                    this.pp(b);
                }
            }
        }
        vu(a, b) {
            super.vu(a, b);
            let c = a;
            let d = this.w8;
            let e = this.w7;
            c.af.clear();
            c.ag.clear();
            c.ae.clear();
            c.ah.clear();
            AxisAnnotationFrameManager.b(c);
            if (this.ul(this.w3)) {
                this.yk(this.w3, c, d, e);
            }
            else {
                for (let f of fromEnum(this.cy.series)) {
                    if (this.ul(f)) {
                        this.yk(f, c, d, e);
                    }
                    if (f.isStacked) {
                        f.n5((g) => {
                            if (this.ul(g)) {
                                this.yk(g, c, d, e);
                            }
                            if (g.dv) {
                                g.n3((h) => {
                                    if (this.ul(h)) {
                                        this.yk(h, c, d, e);
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    if (f.dv) {
                        f.n3((g) => {
                            if (this.ul(g)) {
                                this.yk(g, c, d, e);
                            }
                            return true;
                        });
                    }
                }
            }
        }
        ul(a) {
            if (!super.ul(a)) {
                return false;
            }
            if (this.xt != null) {
                if (a.ep) {
                    let b = a.lu();
                    if (!Base.equalsStatic(this.xt, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.xt, a.name)) {
                        return false;
                    }
                }
            }
            let c = this.vn(a);
            if (!c.c) {
                return false;
            }
            return true;
        }
        oo() {
            super.oo();
            if (!this.at.c && !this.dj()) {
                return;
            }
            if (this.dj()) {
                this.yl(this.ug, false);
            }
            else {
                this.yl(this.ue, false);
            }
        }
        t5() {
            return 1;
        }
        us() {
            return 0.1;
        }
        uv() {
            return -0.4;
        }
        uu() {
            return 0.5;
        }
        wr() {
            return this.t2 == 3 ? this.zo() : null;
        }
        ws() {
            return this.t3 == 3 ? this.zo() : null;
        }
        zo() {
            if (this.zn == null) {
                this.zn = new DoubleCollection();
                this.zn.add(DeviceUtils.g(5));
                this.zn.add(DeviceUtils.g(5));
            }
            return this.zn;
        }
        yk(a, b, c, d) {
            let e = this.vn(a);
            if (!e.c) {
                return;
            }
            let f = e.d;
            f = a.th(f, c, d);
            let g = false;
            let h = this.ss;
            if (h == null) {
                h = this.sw;
            }
            if (h == null) {
                h = a.ss;
                g = true;
            }
            let i = false;
            let j = this.zh;
            if (j == null) {
                if (this.sw != null) {
                    j = this.sw;
                }
                else {
                    j = a.ss;
                    i = true;
                }
            }
            let k = false;
            let l = this.zk;
            if (l == null) {
                if (this.sw != null) {
                    l = this.sw;
                }
                else {
                    l = a.ss;
                    k = true;
                }
            }
            let m = h;
            let n = h;
            let o = j;
            let p = l;
            if (this.zf != null) {
                m = this.zf;
            }
            else if (g) {
                switch (this.t2) {
                    case 0:
                    case 1:
                        m = this.w2.ce(m, this.up);
                        break;
                    case 2:
                        m = this.w2.cg(m, this.up);
                        break;
                    case 4:
                        m = this.w2.cf(m, this.up);
                        break;
                }
            }
            if (this.zg != null) {
                n = this.zg;
            }
            else if (g) {
                switch (this.t3) {
                    case 0:
                    case 1:
                        n = this.w2.ce(n, this.ur);
                        break;
                    case 2:
                        n = this.w2.cg(n, this.ur);
                        break;
                    case 4:
                        n = this.w2.cf(n, this.ur);
                        break;
                }
            }
            if (i) {
                switch (this.t3) {
                    case 1:
                        o = this.w2.ce(o, this.ur);
                        break;
                    case 2:
                        o = this.w2.cg(o, this.ur);
                        break;
                }
            }
            if (k) {
                switch (this.t2) {
                    case 1:
                        p = this.w2.ce(p, this.up);
                        break;
                    case 2:
                        p = this.w2.cg(p, this.up);
                        break;
                }
            }
            b.ae.add(m);
            b.ah.add(n);
            b.af.add(f.y);
            b.ag.add(f.x);
            if (this.w6 && !isNaN_(f.y)) {
                AxisAnnotationFrameManager.c(b, f, a, this.cy, this.getEffectiveViewport(), h, o, this.xb, this.zj, this.zi, this.zp, this.xg, p, this.xh, this.zm, this.zl, this.zq, this.xm, this.zs == 0, this.zr == 0);
            }
        }
        yl(a, b) {
            let c = false;
            if (this.w9 == null) {
                c = true;
                this.xa = new List$1(Axis.$, 0);
                this.w9 = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
            }
            AxisAnnotationFrameManager.d(this, a, c, this.w9, this.xa, b, this.xn, this.xo, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
        }
        yj(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.hk;
            f.ai = e ? this.wq : this.wp;
            f.am = this.ta;
            f.al = this.s9;
            f.ak = this.s9;
            f.aj = this.s8;
            f.ac = this.il;
            return new Tuple$2(Path.$, Number_$type, f, b);
        }
        vx(a, b) {
            super.vx(a, b);
            let c = this.w2.b8;
            let d = a;
            let e = d.af.count;
            let f = 0;
            let g = b.bx.left;
            let h = b.bx.right;
            let i = b.bx.top;
            let j = b.bx.bottom;
            let k = this.zs == 0;
            let l = this.zr == 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.yj(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.yj(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.dj()) {
                this.yl(this.ug, true);
            }
            else {
                this.yl(this.ue, false);
            }
        }
        fm() {
            return true;
        }
        o8(a, b, c, d) {
            super.o8(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (d == null) {
                        if (this.w9 != null && this.w9.count > 0) {
                            let e;
                            if (this.dj()) {
                                e = this.ug;
                            }
                            else {
                                e = this.ue;
                            }
                            AxisAnnotationFrameManager.b(e);
                            AxisAnnotationFrameManager.d(this, e, true, this.w9, this.xa, true, this.xn, this.xo, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                        }
                    }
                    break;
                case CrosshairLayer.$$p[1]:
                    this.pp(true);
                    break;
                case CrosshairLayer.$$p[8]:
                    this.pp(true);
                    break;
                case CrosshairLayer.$$p[4]:
                case CrosshairLayer.$$p[5]:
                    this.pp(true);
                    break;
                case CrosshairLayer.$$p[2]:
                case CrosshairLayer.$$p[10]:
                case CrosshairLayer.$$p[9]:
                case CrosshairLayer.$$p[12]:
                case CrosshairLayer.$$p[14]:
                case CrosshairLayer.$$p[16]:
                case CrosshairLayer.$$p[15]:
                case CrosshairLayer.$$p[13]:
                case CrosshairLayer.$$p[17]:
                case CrosshairLayer.$$p[18]:
                case CrosshairLayer.$$p[20]:
                case CrosshairLayer.$$p[22]:
                case CrosshairLayer.$$p[24]:
                case CrosshairLayer.$$p[26]:
                case CrosshairLayer.$$p[25]:
                case CrosshairLayer.$$p[23]:
                case CrosshairLayer.$$p[27]:
                case CrosshairLayer.$$p[28]:
                case CrosshairLayer.$$p[0]:
                case CrosshairLayer.$$p[7]:
                case CrosshairLayer.$$p[6]:
                    this.pp(true);
                    break;
            }
        }
    }
    CrosshairLayer.$t = /*@__PURE__*/ markType(CrosshairLayer, 'CrosshairLayer', AnnotationLayer.$);
    CrosshairLayer.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CrosshairLayer, 'raisePropertyChanged', ['HorizontalLineStroke:zf:ym', [Brush.$, null], 'HorizontalLineVisibility:zr:yn', [Visibility_$type, /*@__PURE__*/ enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:w6:yo', [0, false], 'SkipUnknownValues:w7:yp', [0, true], 'TargetSeriesName:xt:yq', [2, null], 'TargetSeries:w3:yr', [Series.$, null], 'UseInterpolation:w8:ys', [0, true], 'VerticalLineStroke:zg:yt', [Brush.$, null], 'VerticalLineVisibility:zs:yu', [Visibility_$type, /*@__PURE__*/ enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:xb:yv', [1, /*@__PURE__*/ DeviceUtils.g(3)], 'XAxisAnnotationBackground:zh:yw', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:xn:yx', [1, -1], 'XAxisAnnotationOutline:zi:yy', [Brush.$, null], 'XAxisAnnotationPaddingBottom:xc:yz', [1, NaN], 'XAxisAnnotationPaddingLeft:xd:y0', [1, NaN], 'XAxisAnnotationPaddingRight:xe:y1', [1, NaN], 'XAxisAnnotationPaddingTop:xf:y2', [1, NaN], 'XAxisAnnotationStrokeThickness:xg:y3', [1, NaN], 'XAxisAnnotationTextColor:zj:y4', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:xh:y5', [1, /*@__PURE__*/ DeviceUtils.g(3)], 'YAxisAnnotationBackground:zk:y6', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:xo:y7', [1, -1], 'YAxisAnnotationOutline:zl:y8', [Brush.$, null], 'YAxisAnnotationPaddingBottom:xi:y9', [1, NaN], 'YAxisAnnotationPaddingLeft:xj:za', [1, NaN], 'YAxisAnnotationPaddingRight:xk:zb', [1, NaN], 'YAxisAnnotationPaddingTop:xl:zc', [1, NaN], 'YAxisAnnotationStrokeThickness:xm:zd', [1, NaN], 'YAxisAnnotationTextColor:zm:ze', [Brush.$, null]]);
    return CrosshairLayer;
})();
/**
 * @hidden
 */
export let CrosshairLayerView = /*@__PURE__*/ (() => {
    class CrosshairLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            this.b7 = null;
            this.b8 = null;
            this.b9 = null;
            this.b7 = a;
            this.b9 = new List$1(Path.$, 0);
        }
        au() {
            super.au();
            this.b8 = ((() => {
                let $ret = new Pool$1(Path.$);
                $ret.create = runOn(this, this.ch);
                $ret.activate = runOn(this, this.ca);
                $ret.disactivate = runOn(this, this.cc);
                $ret.destroy = runOn(this, this.cb);
                return $ret;
            })());
            this.b7.iu = Defaults.j;
        }
        ch() {
            let a = new Path();
            a.j = new TranslateTransform();
            this.b9.add(a);
            return a;
        }
        ca(a) {
            a._visibility = 0;
        }
        cc(a) {
            a._visibility = 1;
        }
        cb(a) {
            this.b9.remove(a);
        }
        cd(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;
            }
        }
        ce(a, b) {
            if (a == null) {
                return a;
            }
            return BrushUtil.m(a, b);
        }
        cg(a, b) {
            if (a == null) {
                return a;
            }
            return BrushUtil.o(a, b);
        }
        cf(a, b) {
            if (a == null) {
                return a;
            }
            let c = new Brush();
            c.color = Color.u(truncate((a.color.l * b)), a.color.o, a.color.n, a.color.m);
            return c;
        }
        a8(a, b) {
            super.a8(a, b);
            if (a.d && !b) {
                for (let c = 0; c < this.b9.count; c++) {
                    let d = this.b9._inner[c];
                    if (d._visibility == 0) {
                        a.t(d);
                    }
                }
            }
        }
        an(a) {
            super.an(a);
            for (let b = 0; b < this.b9.count; b++) {
                this.e.a9.exportPathData(a, this.b9._inner[b], "crosshairLine", ["Main", "Crosshair"]);
            }
        }
    }
    CrosshairLayerView.$t = /*@__PURE__*/ markType(CrosshairLayerView, 'CrosshairLayerView', AnnotationLayerView.$);
    return CrosshairLayerView;
})();
