/*
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 { 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 { DeviceUtils } from "igniteui-angular-core";
import { isNaN_ } 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";
/**
 * @hidden
 */
export let CrosshairLayer = /*@__PURE__*/ (() => {
    class CrosshairLayer extends AnnotationLayer {
        constructor() {
            super();
            this.xAxisAnnotationFormatLabel = null;
            this.yAxisAnnotationFormatLabel = null;
            this.rh = null;
            this.rg = null;
            let a = new CrosshairLayerFrame();
            let b = new CrosshairLayerFrame();
            let c = new CrosshairLayerFrame();
            let d = this.hm / 1000;
            this.p5 = a;
            this.p4 = b;
            this.p6 = c;
            this.ab = CrosshairLayer.$;
        }
        get_db() {
            return true;
        }
        get_c9() {
            return true;
        }
        bx() {
            return new CrosshairLayerView(this);
        }
        ly(a) {
            super.ly(a);
            this.q9 = a;
        }
        rb() {
            return this.xAxisAnnotationFormatLabel != null;
        }
        rc() {
            return this.yAxisAnnotationFormatLabel != null;
        }
        get tu() {
            return new Thickness(1, this.rk, this.rm, this.rl, this.rj);
        }
        get tv() {
            return new Thickness(1, this.rq, this.rs, this.rr, this.rp);
        }
        qo(a, b) {
            if (this.ra == null || this.ra == a) {
                if (!this.as.c) {
                    this.mh(b);
                }
            }
        }
        qq(a, b) {
            super.qq(a, b);
            let c = a;
            let d = this.rf;
            let e = this.re;
            c.af.clear();
            c.ag.clear();
            c.ae.clear();
            c.ah.clear();
            AxisAnnotationFrameManager.b(c);
            if (this.qb(this.ra)) {
                this.sr(this.ra, c, d, e);
            }
            else {
                for (let f of fromEnum(this.cd.series)) {
                    if (this.qb(f)) {
                        this.sr(f, c, d, e);
                    }
                    if (f.isStacked) {
                        f.la((g) => {
                            if (this.qb(g)) {
                                this.sr(g, c, d, e);
                            }
                            return true;
                        });
                    }
                }
            }
        }
        qb(a) {
            if (!super.qb(a)) {
                return false;
            }
            if (this.r0 != null) {
                if (a.du) {
                    let b = a.jp();
                    if (!Base.equalsStatic(this.r0, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.r0, a.name)) {
                        return false;
                    }
                }
            }
            let c = this.qj(a);
            if (!c.c) {
                return false;
            }
            return true;
        }
        lr() {
            super.lr();
            if (!this.as.c && !this.cv()) {
                return;
            }
            if (this.cv()) {
                this.ss(this.p6, false);
            }
            else {
                this.ss(this.p4, false);
            }
        }
        sr(a, b, c, d) {
            let e = this.qj(a);
            if (!e.c) {
                return;
            }
            let f = e.d;
            f = a.pl(f, c, d);
            let g = this.oy;
            if (g == null) {
                g = this.o2;
            }
            if (g == null) {
                g = a.oy;
                if (g != null) {
                    g = this.q9.cb(g);
                }
            }
            let h = g;
            let i = g;
            if (this.tm != null) {
                h = this.tm;
            }
            if (this.tn != null) {
                i = this.tn;
            }
            b.ae.add(h);
            b.ah.add(i);
            b.af.add(f.y);
            b.ag.add(f.x);
            if (this.rd && !isNaN_(f.y)) {
                AxisAnnotationFrameManager.c(b, f, a, this.cd, this.getEffectiveViewport(), g, this.to, this.ri, this.tq, this.tp, this.tu, this.rn, this.tr, this.ro, this.tt, this.ts, this.tv, this.rt, this.tx == 0, this.tw == 0);
            }
        }
        ss(a, b) {
            let c = false;
            if (this.rg == null) {
                c = true;
                this.rh = new List$1(Axis.$, 0);
                this.rg = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
            }
            AxisAnnotationFrameManager.d(this, a, c, this.rg, this.rh, b, this.ru, this.rv, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
        }
        sq(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.ac = this.fu;
            f.ai = this.pb;
            f.ad = this.pc;
            return new Tuple$2(Path.$, Number_$type, f, b);
        }
        qt(a, b) {
            super.qt(a, b);
            let c = this.q9.b5;
            let d = a;
            let e = d.af.count;
            let f = 0;
            let g = b.bu.left;
            let h = b.bu.right;
            let i = b.bu.top;
            let j = b.bu.bottom;
            let k = this.tx == 0;
            let l = this.tw == 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.sq(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.ak = r;
                }
                if (l) {
                    if (isNaN_(n)) {
                        continue;
                    }
                    let u = this.sq(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.ak = v;
                }
            }
            c.count = f;
            if (this.cv()) {
                this.ss(this.p6, true);
            }
            else {
                this.ss(this.p4, false);
            }
        }
        em() {
            return true;
        }
        l3(a, b, c, d) {
            super.l3(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (d == null) {
                        if (this.rg != null && this.rg.count > 0) {
                            let e;
                            if (this.cv()) {
                                e = this.p6;
                            }
                            else {
                                e = this.p4;
                            }
                            AxisAnnotationFrameManager.b(e);
                            AxisAnnotationFrameManager.d(this, e, true, this.rg, this.rh, true, this.ru, this.rv, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                        }
                    }
                    break;
                case CrosshairLayer.$$p[1]:
                    this.mh(true);
                    break;
                case CrosshairLayer.$$p[8]:
                    this.mh(true);
                    break;
                case CrosshairLayer.$$p[4]:
                case CrosshairLayer.$$p[5]:
                    this.mh(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.mh(true);
                    break;
            }
        }
    }
    CrosshairLayer.$t = markType(CrosshairLayer, 'CrosshairLayer', AnnotationLayer.$);
    CrosshairLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CrosshairLayer, 'raisePropertyChanged', ['HorizontalLineStroke:tm:st', [Brush.$, null], 'HorizontalLineVisibility:tw:su', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:rd:sv', [0, false], 'SkipUnknownValues:re:sw', [0, true], 'TargetSeriesName:r0:sx', [2, null], 'TargetSeries:ra:sy', [Series.$, null], 'UseInterpolation:rf:sz', [0, true], 'VerticalLineStroke:tn:s0', [Brush.$, null], 'VerticalLineVisibility:tx:s1', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:ri:s2', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:to:s3', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:ru:s4', [1, -1], 'XAxisAnnotationOutline:tp:s5', [Brush.$, null], 'XAxisAnnotationPaddingBottom:rj:s6', [1, NaN], 'XAxisAnnotationPaddingLeft:rk:s7', [1, NaN], 'XAxisAnnotationPaddingRight:rl:s8', [1, NaN], 'XAxisAnnotationPaddingTop:rm:s9', [1, NaN], 'XAxisAnnotationStrokeThickness:rn:ta', [1, NaN], 'XAxisAnnotationTextColor:tq:tb', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:ro:tc', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:tr:td', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:rv:te', [1, -1], 'YAxisAnnotationOutline:ts:tf', [Brush.$, null], 'YAxisAnnotationPaddingBottom:rp:tg', [1, NaN], 'YAxisAnnotationPaddingLeft:rq:th', [1, NaN], 'YAxisAnnotationPaddingRight:rr:ti', [1, NaN], 'YAxisAnnotationPaddingTop:rs:tj', [1, NaN], 'YAxisAnnotationStrokeThickness:rt:tk', [1, NaN], 'YAxisAnnotationTextColor:tt:tl', [Brush.$, null]]);
    return CrosshairLayer;
})();
/**
 * @hidden
 */
export let CrosshairLayerView = /*@__PURE__*/ (() => {
    class CrosshairLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            this.b4 = null;
            this.b5 = null;
            this.b6 = null;
            this.b4 = a;
            this.b6 = new List$1(Path.$, 0);
        }
        as() {
            super.as();
            this.b5 = ((() => {
                let $ret = new Pool$1(Path.$);
                $ret.create = runOn(this, this.cc);
                $ret.activate = runOn(this, this.b7);
                $ret.disactivate = runOn(this, this.b9);
                $ret.destroy = runOn(this, this.b8);
                return $ret;
            })());
            this.b4.gz = Defaults.j;
        }
        cc() {
            let a = new Path();
            a.j = new TranslateTransform();
            this.b6.add(a);
            return a;
        }
        b7(a) {
            a._visibility = 0;
        }
        b9(a) {
            a._visibility = 1;
        }
        b8(a) {
            this.b6.remove(a);
        }
        ca(a, b, c, d) {
            if (a.ak == null || a.ak.c.x != d || a.ak.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.ak = e;
            }
        }
        cb(a) {
            if (a == null) {
                return a;
            }
            return BrushUtil.l(a, 0.1);
        }
        a6(a, b) {
            super.a6(a, b);
            if (a.d && !b) {
                for (let c = 0; c < this.b6.count; c++) {
                    let d = this.b6._inner[c];
                    if (d._visibility == 0) {
                        a.s(d);
                    }
                }
            }
        }
        al(a) {
            super.al(a);
            for (let b = 0; b < this.b6.count; b++) {
                this.e.a8.exportPathData(a, this.b6._inner[b], "crosshairLine", ["Main", "Crosshair"]);
            }
        }
    }
    CrosshairLayerView.$t = markType(CrosshairLayerView, 'CrosshairLayerView', AnnotationLayerView.$);
    return CrosshairLayerView;
})();
