/*
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 {
        bc() {
            return new CrosshairLayer();
        }
        get_d6() {
            return true;
        }
        get_d4() {
            return true;
        }
        constructor() {
            super();
            this.xAxisAnnotationFormatLabel = null;
            this.yAxisAnnotationFormatLabel = null;
            this.zp = null;
            this.xc = null;
            this.xb = null;
            let a = new CrosshairLayerFrame();
            let b = new CrosshairLayerFrame();
            let c = new CrosshairLayerFrame();
            let d = this.jj / 1000;
            this.uh = a;
            this.ug = b;
            this.ui = c;
            this.ab = CrosshairLayer.$;
        }
        cd() {
            return new CrosshairLayerView(this);
        }
        o2(a) {
            super.o2(a);
            this.w4 = a;
        }
        w6() {
            return this.xAxisAnnotationFormatLabel != null;
        }
        w7() {
            return this.yAxisAnnotationFormatLabel != null;
        }
        get zr() {
            return new Thickness(1, this.xf, this.xh, this.xg, this.xe);
        }
        get zs() {
            return new Thickness(1, this.xl, this.xn, this.xm, this.xk);
        }
        vu(a, b) {
            if (this.w5 == null || this.w5 == a) {
                if (!this.at.c) {
                    this.pr(b);
                }
            }
        }
        vw(a, b) {
            super.vw(a, b);
            let c = a;
            let d = this.xa;
            let e = this.w9;
            c.af.clear();
            c.ag.clear();
            c.ae.clear();
            c.ah.clear();
            AxisAnnotationFrameManager.b(c);
            if (this.un(this.w5)) {
                this.ym(this.w5, c, d, e);
            }
            else {
                for (let f of fromEnum(this.cv.series)) {
                    if (this.un(f)) {
                        this.ym(f, c, d, e);
                    }
                    if (f.isStacked) {
                        f.n6((g) => {
                            if (this.un(g)) {
                                this.ym(g, c, d, e);
                            }
                            if (g.dw) {
                                g.n4((h) => {
                                    if (this.un(h)) {
                                        this.ym(h, c, d, e);
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    if (f.dw) {
                        f.n4((g) => {
                            if (this.un(g)) {
                                this.ym(g, c, d, e);
                            }
                            return true;
                        });
                    }
                }
            }
        }
        un(a) {
            if (!super.un(a)) {
                return false;
            }
            if (this.xv != null) {
                if (a.eq) {
                    let b = a.lv();
                    if (!Base.equalsStatic(this.xv, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.xv, a.name)) {
                        return false;
                    }
                }
            }
            let c = this.vp(a);
            if (!c.c) {
                return false;
            }
            return true;
        }
        oq() {
            super.oq();
            if (!this.at.c && !this.dk()) {
                return;
            }
            if (this.dk()) {
                this.yn(this.ui, false);
            }
            else {
                this.yn(this.ug, false);
            }
        }
        t7() {
            return 1;
        }
        uu() {
            return 0.1;
        }
        ux() {
            return -0.4;
        }
        uw() {
            return 0.5;
        }
        wt() {
            return this.t4 == 3 ? this.zq() : null;
        }
        wu() {
            return this.t5 == 3 ? this.zq() : null;
        }
        zq() {
            if (this.zp == null) {
                this.zp = new DoubleCollection();
                this.zp.add(DeviceUtils.g(5));
                this.zp.add(DeviceUtils.g(5));
            }
            return this.zp;
        }
        ym(a, b, c, d) {
            let e = this.vp(a);
            if (!e.c) {
                return;
            }
            let f = e.d;
            f = a.tj(f, c, d);
            let g = false;
            let h = this.su;
            if (h == null) {
                h = this.sy;
            }
            if (h == null) {
                h = a.su;
                g = true;
            }
            let i = false;
            let j = this.zj;
            if (j == null) {
                if (this.sy != null) {
                    j = this.sy;
                }
                else {
                    j = a.su;
                    i = true;
                }
            }
            let k = false;
            let l = this.zm;
            if (l == null) {
                if (this.sy != null) {
                    l = this.sy;
                }
                else {
                    l = a.su;
                    k = true;
                }
            }
            let m = h;
            let n = h;
            let o = j;
            let p = l;
            if (this.zh != null) {
                m = this.zh;
            }
            else if (g) {
                switch (this.t4) {
                    case 0:
                    case 1:
                        m = this.w4.ce(m, this.ur);
                        break;
                    case 2:
                        m = this.w4.cg(m, this.ur);
                        break;
                    case 4:
                        m = this.w4.cf(m, this.ur);
                        break;
                }
            }
            if (this.zi != null) {
                n = this.zi;
            }
            else if (g) {
                switch (this.t5) {
                    case 0:
                    case 1:
                        n = this.w4.ce(n, this.ut);
                        break;
                    case 2:
                        n = this.w4.cg(n, this.ut);
                        break;
                    case 4:
                        n = this.w4.cf(n, this.ut);
                        break;
                }
            }
            if (i) {
                switch (this.t5) {
                    case 1:
                        o = this.w4.ce(o, this.ut);
                        break;
                    case 2:
                        o = this.w4.cg(o, this.ut);
                        break;
                }
            }
            if (k) {
                switch (this.t4) {
                    case 1:
                        p = this.w4.ce(p, this.ur);
                        break;
                    case 2:
                        p = this.w4.cg(p, this.ur);
                        break;
                }
            }
            b.ae.add(m);
            b.ah.add(n);
            b.af.add(f.y);
            b.ag.add(f.x);
            if (this.w8 && !isNaN_(f.y)) {
                AxisAnnotationFrameManager.c(b, f, a, this.cv, this.getEffectiveViewport(), h, o, this.xd, this.zl, this.zk, this.zr, this.xi, p, this.xj, this.zo, this.zn, this.zs, this.xo, this.zu == 0, this.zt == 0);
            }
        }
        yn(a, b) {
            let c = false;
            if (this.xb == null) {
                c = true;
                this.xc = new List$1(Axis.$, 0);
                this.xb = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
            }
            AxisAnnotationFrameManager.d(this, a, c, this.xb, this.xc, b, this.xp, this.xq, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
        }
        yl(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.hl;
            f.ai = e ? this.ws : this.wr;
            f.am = this.tc;
            f.al = this.tb;
            f.ak = this.tb;
            f.aj = this.ta;
            f.ac = this.im;
            return new Tuple$2(Path.$, Number_$type, f, b);
        }
        vz(a, b) {
            super.vz(a, b);
            let c = this.w4.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.zu == 0;
            let l = this.zt == 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.yl(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.yl(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.dk()) {
                this.yn(this.ui, true);
            }
            else {
                this.yn(this.ug, false);
            }
        }
        fn() {
            return true;
        }
        pa(a, b, c, d) {
            super.pa(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (d == null) {
                        if (this.xb != null && this.xb.count > 0) {
                            let e;
                            if (this.dk()) {
                                e = this.ui;
                            }
                            else {
                                e = this.ug;
                            }
                            AxisAnnotationFrameManager.b(e);
                            AxisAnnotationFrameManager.d(this, e, true, this.xb, this.xc, true, this.xp, this.xq, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                        }
                    }
                    break;
                case CrosshairLayer.$$p[1]:
                    this.pr(true);
                    break;
                case CrosshairLayer.$$p[8]:
                    this.pr(true);
                    break;
                case CrosshairLayer.$$p[4]:
                case CrosshairLayer.$$p[5]:
                    this.pr(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.pr(true);
                    break;
            }
        }
    }
    CrosshairLayer.$t = /*@__PURE__*/ markType(CrosshairLayer, 'CrosshairLayer', AnnotationLayer.$);
    CrosshairLayer.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CrosshairLayer, 'raisePropertyChanged', ['HorizontalLineStroke:zh:yo', [Brush.$, null], 'HorizontalLineVisibility:zt:yp', [Visibility_$type, /*@__PURE__*/ enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:w8:yq', [0, false], 'SkipUnknownValues:w9:yr', [0, true], 'TargetSeriesName:xv:ys', [2, null], 'TargetSeries:w5:yt', [Series.$, null], 'UseInterpolation:xa:yu', [0, true], 'VerticalLineStroke:zi:yv', [Brush.$, null], 'VerticalLineVisibility:zu:yw', [Visibility_$type, /*@__PURE__*/ enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:xd:yx', [1, /*@__PURE__*/ DeviceUtils.g(3)], 'XAxisAnnotationBackground:zj:yy', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:xp:yz', [1, -1], 'XAxisAnnotationOutline:zk:y0', [Brush.$, null], 'XAxisAnnotationPaddingBottom:xe:y1', [1, NaN], 'XAxisAnnotationPaddingLeft:xf:y2', [1, NaN], 'XAxisAnnotationPaddingRight:xg:y3', [1, NaN], 'XAxisAnnotationPaddingTop:xh:y4', [1, NaN], 'XAxisAnnotationStrokeThickness:xi:y5', [1, NaN], 'XAxisAnnotationTextColor:zl:y6', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:xj:y7', [1, /*@__PURE__*/ DeviceUtils.g(3)], 'YAxisAnnotationBackground:zm:y8', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:xq:y9', [1, -1], 'YAxisAnnotationOutline:zn:za', [Brush.$, null], 'YAxisAnnotationPaddingBottom:xk:zb', [1, NaN], 'YAxisAnnotationPaddingLeft:xl:zc', [1, NaN], 'YAxisAnnotationPaddingRight:xm:zd', [1, NaN], 'YAxisAnnotationPaddingTop:xn:ze', [1, NaN], 'YAxisAnnotationStrokeThickness:xo:zf', [1, NaN], 'YAxisAnnotationTextColor:zo:zg', [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.iv = 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.a5.exportPathData(a, this.b9._inner[b], "crosshairLine", ["Main", "Crosshair"]);
            }
        }
    }
    CrosshairLayerView.$t = /*@__PURE__*/ markType(CrosshairLayerView, 'CrosshairLayerView', AnnotationLayerView.$);
    return CrosshairLayerView;
})();
