/*
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 {
        bj() {
            return new CrosshairLayer();
        }
        get_er() {
            return true;
        }
        get_ep() {
            return true;
        }
        constructor() {
            super();
            this.xAxisAnnotationFormatLabel = null;
            this.yAxisAnnotationFormatLabel = null;
            this.aci = null;
            this.z5 = null;
            this.z4 = null;
            let a = new CrosshairLayerFrame();
            let b = new CrosshairLayerFrame();
            let c = new CrosshairLayerFrame();
            let d = this.kd / 1000;
            this.xa = a;
            this.w9 = b;
            this.xb = c;
            this.ab = CrosshairLayer.$;
        }
        cs() {
            return new CrosshairLayerView(this);
        }
        qz(a) {
            super.qz(a);
            this.zx = a;
        }
        gu(a) {
            if (this.zy == null) {
                return true;
            }
            if (this.zy == a) {
                return true;
            }
            return false;
        }
        zz() {
            return this.xAxisAnnotationFormatLabel != null;
        }
        z0() {
            return this.yAxisAnnotationFormatLabel != null;
        }
        get ack() {
            return new Thickness(1, this.z8, this.aaa, this.z9, this.z7);
        }
        get acl() {
            return new Thickness(1, this.aae, this.aag, this.aaf, this.aad);
        }
        yn(a, b) {
            if (this.zy == null || this.zy == a) {
                if (!this.a1.c) {
                    this.rp(b);
                }
            }
        }
        yp(a, b) {
            super.yp(a, b);
            let c = a;
            let d = this.z3;
            let e = this.z2;
            c.af.clear();
            c.ag.clear();
            c.ae.clear();
            c.ah.clear();
            AxisAnnotationFrameManager.b(c);
            if (this.xg(this.zy)) {
                this.abf(this.zy, c, d, e);
            }
            else {
                for (let f of fromEnum(this.db.series)) {
                    if (this.xg(f)) {
                        this.abf(f, c, d, e);
                    }
                    if (f.isStacked) {
                        f.p1((g) => {
                            if (this.xg(g)) {
                                this.abf(g, c, d, e);
                            }
                            if (g.eg) {
                                g.pz((h) => {
                                    if (this.xg(h)) {
                                        this.abf(h, c, d, e);
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    if (f.eg) {
                        f.pz((g) => {
                            if (this.xg(g)) {
                                this.abf(g, c, d, e);
                            }
                            return true;
                        });
                    }
                }
            }
        }
        xg(a) {
            if (!super.xg(a)) {
                return false;
            }
            if (this.aao != null) {
                if (a.fb) {
                    let b = a.nc();
                    if (!Base.equalsStatic(this.aao, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.aao, a.name)) {
                        return false;
                    }
                }
            }
            let c = this.yi(a);
            if (!c.c) {
                return false;
            }
            return true;
        }
        qn() {
            super.qn();
            if (!this.a1.c && !this.d3()) {
                return;
            }
            if (this.d3()) {
                this.abg(this.xb, false);
            }
            else {
                this.abg(this.w9, false);
            }
        }
        w0() {
            return 1;
        }
        xn() {
            return 0.1;
        }
        xq() {
            return -0.4;
        }
        xp() {
            return 0.5;
        }
        zm() {
            return this.wx == 3 ? this.acj() : null;
        }
        zn() {
            return this.wy == 3 ? this.acj() : null;
        }
        acj() {
            if (this.aci == null) {
                this.aci = new DoubleCollection();
                this.aci.add(DeviceUtils.g(5));
                this.aci.add(DeviceUtils.g(5));
            }
            return this.aci;
        }
        abf(a, b, c, d) {
            let e = this.yi(a);
            if (!e.c) {
                return;
            }
            let f = e.d;
            f = a.wa(f, c, d);
            let g = false;
            let h = this.u7;
            if (h == null) {
                h = this.vd;
            }
            if (h == null) {
                h = a.u7;
                g = true;
            }
            let i = false;
            let j = this.acc;
            if (j == null) {
                if (this.vd != null) {
                    j = this.vd;
                }
                else {
                    j = a.u7;
                    i = true;
                }
            }
            let k = false;
            let l = this.acf;
            if (l == null) {
                if (this.vd != null) {
                    l = this.vd;
                }
                else {
                    l = a.u7;
                    k = true;
                }
            }
            let m = h;
            let n = h;
            let o = j;
            let p = l;
            if (this.aca != null) {
                m = this.aca;
            }
            else if (g) {
                switch (this.wx) {
                    case 0:
                    case 1:
                        m = this.zx.ce(m, this.xk);
                        break;
                    case 2:
                        m = this.zx.cg(m, this.xk);
                        break;
                    case 4:
                        m = this.zx.cf(m, this.xk);
                        break;
                }
            }
            if (this.acb != null) {
                n = this.acb;
            }
            else if (g) {
                switch (this.wy) {
                    case 0:
                    case 1:
                        n = this.zx.ce(n, this.xm);
                        break;
                    case 2:
                        n = this.zx.cg(n, this.xm);
                        break;
                    case 4:
                        n = this.zx.cf(n, this.xm);
                        break;
                }
            }
            if (i) {
                switch (this.wy) {
                    case 1:
                        o = this.zx.ce(o, this.xm);
                        break;
                    case 2:
                        o = this.zx.cg(o, this.xm);
                        break;
                }
            }
            if (k) {
                switch (this.wx) {
                    case 1:
                        p = this.zx.ce(p, this.xk);
                        break;
                    case 2:
                        p = this.zx.cg(p, this.xk);
                        break;
                }
            }
            b.ae.add(m);
            b.ah.add(n);
            b.af.add(f.y);
            b.ag.add(f.x);
            if (this.z1 && !isNaN_(f.y)) {
                AxisAnnotationFrameManager.c(b, f, a, this.db, this.getEffectiveViewport(), h, o, this.z6, this.ace, this.acd, this.ack, this.aab, p, this.aac, this.ach, this.acg, this.acl, this.aah, this.acn == 0, this.acm == 0);
            }
        }
        abg(a, b) {
            let c = false;
            if (this.z4 == null) {
                c = true;
                this.z5 = new List$1(Axis.$, 0);
                this.z4 = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
            }
            AxisAnnotationFrameManager.d(this, a, c, this.z4, this.z5, b, this.aai, this.aaj, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
        }
        abe(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.ie;
            f.ai = e ? this.zl : this.zk;
            f.am = this.v3;
            f.al = this.v2;
            f.ak = this.v2;
            f.aj = this.v1;
            f.ac = this.jh;
            return new Tuple$2(Path.$, Number_$type, f, b);
        }
        ys(a, b) {
            super.ys(a, b);
            let c = this.zx.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.acn == 0;
            let l = this.acm == 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.abe(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.abe(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.d3()) {
                this.abg(this.xb, true);
            }
            else {
                this.abg(this.w9, false);
            }
        }
        ga() {
            return true;
        }
        q7(a, b, c, d) {
            super.q7(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (d == null) {
                        if (this.z4 != null && this.z4.count > 0) {
                            let e;
                            if (this.d3()) {
                                e = this.xb;
                            }
                            else {
                                e = this.w9;
                            }
                            AxisAnnotationFrameManager.b(e);
                            AxisAnnotationFrameManager.d(this, e, true, this.z4, this.z5, true, this.aai, this.aaj, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                        }
                    }
                    break;
                case CrosshairLayer.$$p[1]:
                    this.rp(true);
                    break;
                case CrosshairLayer.$$p[8]:
                    this.rp(true);
                    break;
                case CrosshairLayer.$$p[4]:
                case CrosshairLayer.$$p[5]:
                    this.rp(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.rp(true);
                    break;
            }
        }
    }
    CrosshairLayer.$t = /*@__PURE__*/ markType(CrosshairLayer, 'CrosshairLayer', AnnotationLayer.$);
    CrosshairLayer.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CrosshairLayer, 'raisePropertyChanged', ['HorizontalLineStroke:aca:abh', [Brush.$, null], 'HorizontalLineVisibility:acm:abi', [Visibility_$type, /*@__PURE__*/ enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:z1:abj', [0, false], 'SkipUnknownValues:z2:abk', [0, true], 'TargetSeriesName:aao:abl', [2, null], 'TargetSeries:zy:abm', [Series.$, null], 'UseInterpolation:z3:abn', [0, true], 'VerticalLineStroke:acb:abo', [Brush.$, null], 'VerticalLineVisibility:acn:abp', [Visibility_$type, /*@__PURE__*/ enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:z6:abq', [1, /*@__PURE__*/ DeviceUtils.g(3)], 'XAxisAnnotationBackground:acc:abr', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:aai:abs', [1, -1], 'XAxisAnnotationOutline:acd:abt', [Brush.$, null], 'XAxisAnnotationPaddingBottom:z7:abu', [1, NaN], 'XAxisAnnotationPaddingLeft:z8:abv', [1, NaN], 'XAxisAnnotationPaddingRight:z9:abw', [1, NaN], 'XAxisAnnotationPaddingTop:aaa:abx', [1, NaN], 'XAxisAnnotationStrokeThickness:aab:aby', [1, NaN], 'XAxisAnnotationTextColor:ace:abz', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:aac:ab0', [1, /*@__PURE__*/ DeviceUtils.g(3)], 'YAxisAnnotationBackground:acf:ab1', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:aaj:ab2', [1, -1], 'YAxisAnnotationOutline:acg:ab3', [Brush.$, null], 'YAxisAnnotationPaddingBottom:aad:ab4', [1, NaN], 'YAxisAnnotationPaddingLeft:aae:ab5', [1, NaN], 'YAxisAnnotationPaddingRight:aaf:ab6', [1, NaN], 'YAxisAnnotationPaddingTop:aag:ab7', [1, NaN], 'YAxisAnnotationStrokeThickness:aah:ab8', [1, NaN], 'YAxisAnnotationTextColor:ach:ab9', [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.jp = 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.bc.exportPathData(a, this.b9._inner[b], "crosshairLine", ["Main", "Crosshair"]);
            }
        }
    }
    CrosshairLayerView.$t = /*@__PURE__*/ markType(CrosshairLayerView, 'CrosshairLayerView', AnnotationLayerView.$);
    return CrosshairLayerView;
})();
