/*
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 { 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_, truncate } from "igniteui-angular-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { Defaults } from "./Defaults";
import { TranslateTransform } from "igniteui-angular-core";
import { LineGeometry } from "igniteui-angular-core";
import { BrushUtil } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
/**
 * @hidden
 */
export let CrosshairLayer = /*@__PURE__*/ (() => {
    class CrosshairLayer extends AnnotationLayer {
        constructor() {
            super();
            this.xAxisAnnotationFormatLabel = null;
            this.yAxisAnnotationFormatLabel = null;
            this.ack = null;
            this.z7 = null;
            this.z6 = null;
            let a = new CrosshairLayerFrame();
            let b = new CrosshairLayerFrame();
            let c = new CrosshairLayerFrame();
            let d = this.kd / 1000;
            this.xc = a;
            this.xb = b;
            this.xd = c;
            this.ab = CrosshairLayer.$;
        }
        bj() {
            return new CrosshairLayer();
        }
        get_er() {
            return true;
        }
        get_ep() {
            return true;
        }
        cs() {
            return new CrosshairLayerView(this);
        }
        q1(a) {
            super.q1(a);
            this.zz = a;
        }
        gu(a) {
            if (this.z0 == null) {
                return true;
            }
            if (this.z0 == a) {
                return true;
            }
            return false;
        }
        z1() {
            return this.xAxisAnnotationFormatLabel != null;
        }
        z2() {
            return this.yAxisAnnotationFormatLabel != null;
        }
        get acm() {
            return new Thickness(1, this.aaa, this.aac, this.aab, this.z9);
        }
        get acn() {
            return new Thickness(1, this.aag, this.aai, this.aah, this.aaf);
        }
        yp(a, b) {
            if (this.z0 == null || this.z0 == a) {
                if (!this.a1.c) {
                    this.rr(b);
                }
            }
        }
        yr(a, b) {
            super.yr(a, b);
            let c = a;
            let d = this.z5;
            let e = this.z4;
            c.af.clear();
            c.ag.clear();
            c.ae.clear();
            c.ah.clear();
            AxisAnnotationFrameManager.b(c);
            if (this.xi(this.z0)) {
                this.abh(this.z0, c, d, e);
            }
            else {
                for (let f of fromEnum(this.db.series)) {
                    if (this.xi(f)) {
                        this.abh(f, c, d, e);
                    }
                    if (f.isStacked) {
                        f.p3((g) => {
                            if (this.xi(g)) {
                                this.abh(g, c, d, e);
                            }
                            if (g.eg) {
                                g.p1((h) => {
                                    if (this.xi(h)) {
                                        this.abh(h, c, d, e);
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    if (f.eg) {
                        f.p1((g) => {
                            if (this.xi(g)) {
                                this.abh(g, c, d, e);
                            }
                            return true;
                        });
                    }
                }
            }
        }
        xi(a) {
            if (!super.xi(a)) {
                return false;
            }
            if (this.aaq != null) {
                if (a.fb) {
                    let b = a.nc();
                    if (!Base.equalsStatic(this.aaq, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.aaq, a.name)) {
                        return false;
                    }
                }
            }
            let c = this.yk(a);
            if (!c.c) {
                return false;
            }
            return true;
        }
        qp() {
            super.qp();
            if (!this.a1.c && !this.d3()) {
                return;
            }
            if (this.d3()) {
                this.abi(this.xd, false);
            }
            else {
                this.abi(this.xb, false);
            }
        }
        w2() {
            return 1;
        }
        xp() {
            return 0.1;
        }
        xs() {
            return -0.4;
        }
        xr() {
            return 0.5;
        }
        zo() {
            return this.wz == 3 ? this.acl() : null;
        }
        zp() {
            return this.w0 == 3 ? this.acl() : null;
        }
        acl() {
            if (this.ack == null) {
                this.ack = new DoubleCollection();
                this.ack.add(DeviceUtils.g(5));
                this.ack.add(DeviceUtils.g(5));
            }
            return this.ack;
        }
        abh(a, b, c, d) {
            let e = this.yk(a);
            if (!e.c) {
                return;
            }
            let f = e.d;
            f = a.wc(f, c, d);
            let g = false;
            let h = this.u9;
            if (h == null) {
                h = this.vf;
            }
            if (h == null) {
                h = a.u9;
                g = true;
            }
            let i = false;
            let j = this.ace;
            if (j == null) {
                if (this.vf != null) {
                    j = this.vf;
                }
                else {
                    j = a.u9;
                    i = true;
                }
            }
            let k = false;
            let l = this.ach;
            if (l == null) {
                if (this.vf != null) {
                    l = this.vf;
                }
                else {
                    l = a.u9;
                    k = true;
                }
            }
            let m = h;
            let n = h;
            let o = j;
            let p = l;
            if (this.acc != null) {
                m = this.acc;
            }
            else if (g) {
                switch (this.wz) {
                    case 0:
                    case 1:
                        m = this.zz.ce(m, this.xm);
                        break;
                    case 2:
                        m = this.zz.cg(m, this.xm);
                        break;
                    case 4:
                        m = this.zz.cf(m, this.xm);
                        break;
                }
            }
            if (this.acd != null) {
                n = this.acd;
            }
            else if (g) {
                switch (this.w0) {
                    case 0:
                    case 1:
                        n = this.zz.ce(n, this.xo);
                        break;
                    case 2:
                        n = this.zz.cg(n, this.xo);
                        break;
                    case 4:
                        n = this.zz.cf(n, this.xo);
                        break;
                }
            }
            if (i) {
                switch (this.w0) {
                    case 1:
                        o = this.zz.ce(o, this.xo);
                        break;
                    case 2:
                        o = this.zz.cg(o, this.xo);
                        break;
                }
            }
            if (k) {
                switch (this.wz) {
                    case 1:
                        p = this.zz.ce(p, this.xm);
                        break;
                    case 2:
                        p = this.zz.cg(p, this.xm);
                        break;
                }
            }
            b.ae.add(m);
            b.ah.add(n);
            b.af.add(f.y);
            b.ag.add(f.x);
            if (this.z3 && !isNaN_(f.y)) {
                AxisAnnotationFrameManager.c(b, f, a, this.db, this.getEffectiveViewport(), h, o, this.z8, this.acg, this.acf, this.acm, this.aad, p, this.aae, this.acj, this.aci, this.acn, this.aaj, this.acp == 0, this.aco == 0);
            }
        }
        abi(a, b) {
            let c = false;
            if (this.z6 == null) {
                c = true;
                this.z7 = new List$1(Axis.$, 0);
                this.z6 = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
            }
            AxisAnnotationFrameManager.d(this, a, c, this.z6, this.z7, b, this.aak, this.aal, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
        }
        abg(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.zn : this.zm;
            f.am = this.v5;
            f.al = this.v4;
            f.ak = this.v4;
            f.aj = this.v3;
            f.ac = this.jh;
            return new Tuple$2(Path.$, Number_$type, f, b);
        }
        yu(a, b) {
            super.yu(a, b);
            let c = this.zz.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.acp == 0;
            let l = this.aco == 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.abg(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.abg(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.abi(this.xd, true);
            }
            else {
                this.abi(this.xb, false);
            }
        }
        ga() {
            return true;
        }
        q9(a, b, c, d) {
            super.q9(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (d == null) {
                        if (this.z6 != null && this.z6.count > 0) {
                            let e;
                            if (this.d3()) {
                                e = this.xd;
                            }
                            else {
                                e = this.xb;
                            }
                            AxisAnnotationFrameManager.b(e);
                            AxisAnnotationFrameManager.d(this, e, true, this.z6, this.z7, true, this.aak, this.aal, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                        }
                    }
                    break;
                case CrosshairLayer.$$p[1]:
                    this.rr(true);
                    break;
                case CrosshairLayer.$$p[8]:
                    this.rr(true);
                    break;
                case CrosshairLayer.$$p[4]:
                case CrosshairLayer.$$p[5]:
                    this.rr(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.rr(true);
                    break;
            }
        }
    }
    CrosshairLayer.$t = markType(CrosshairLayer, 'CrosshairLayer', AnnotationLayer.$);
    CrosshairLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CrosshairLayer, 'raisePropertyChanged', ['HorizontalLineStroke:acc:abj', [Brush.$, null], 'HorizontalLineVisibility:aco:abk', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:z3:abl', [0, false], 'SkipUnknownValues:z4:abm', [0, true], 'TargetSeriesName:aaq:abn', [2, null], 'TargetSeries:z0:abo', [Series.$, null], 'UseInterpolation:z5:abp', [0, true], 'VerticalLineStroke:acd:abq', [Brush.$, null], 'VerticalLineVisibility:acp:abr', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:z8:abs', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:ace:abt', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:aak:abu', [1, -1], 'XAxisAnnotationOutline:acf:abv', [Brush.$, null], 'XAxisAnnotationPaddingBottom:z9:abw', [1, NaN], 'XAxisAnnotationPaddingLeft:aaa:abx', [1, NaN], 'XAxisAnnotationPaddingRight:aab:aby', [1, NaN], 'XAxisAnnotationPaddingTop:aac:abz', [1, NaN], 'XAxisAnnotationStrokeThickness:aad:ab0', [1, NaN], 'XAxisAnnotationTextColor:acg:ab1', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:aae:ab2', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:ach:ab3', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:aal:ab4', [1, -1], 'YAxisAnnotationOutline:aci:ab5', [Brush.$, null], 'YAxisAnnotationPaddingBottom:aaf:ab6', [1, NaN], 'YAxisAnnotationPaddingLeft:aag:ab7', [1, NaN], 'YAxisAnnotationPaddingRight:aah:ab8', [1, NaN], 'YAxisAnnotationPaddingTop:aai:ab9', [1, NaN], 'YAxisAnnotationStrokeThickness:aaj:aca', [1, NaN], 'YAxisAnnotationTextColor:acj:acb', [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 = markType(CrosshairLayerView, 'CrosshairLayerView', AnnotationLayerView.$);
    return CrosshairLayerView;
})();
