/*
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.vy = null;
            this.tl = null;
            this.tk = null;
            let a = new CrosshairLayerFrame();
            let b = new CrosshairLayerFrame();
            let c = new CrosshairLayerFrame();
            let d = this.hr / 1000;
            this.qq = a;
            this.qp = b;
            this.qr = c;
            this.ab = CrosshairLayer.$;
        }
        get_dc() {
            return true;
        }
        get_da() {
            return true;
        }
        by() {
            return new CrosshairLayerView(this);
        }
        l4(a) {
            super.l4(a);
            this.td = a;
        }
        tf() {
            return this.xAxisAnnotationFormatLabel != null;
        }
        tg() {
            return this.yAxisAnnotationFormatLabel != null;
        }
        get v0() {
            return new Thickness(1, this.to, this.tq, this.tp, this.tn);
        }
        get v1() {
            return new Thickness(1, this.tu, this.tw, this.tv, this.tt);
        }
        r3(a, b) {
            if (this.te == null || this.te == a) {
                if (!this.at.c) {
                    this.mn(b);
                }
            }
        }
        r5(a, b) {
            super.r5(a, b);
            let c = a;
            let d = this.tj;
            let e = this.ti;
            c.af.clear();
            c.ag.clear();
            c.ae.clear();
            c.ah.clear();
            AxisAnnotationFrameManager.b(c);
            if (this.qw(this.te)) {
                this.uv(this.te, c, d, e);
            }
            else {
                for (let f of fromEnum(this.ce.series)) {
                    if (this.qw(f)) {
                        this.uv(f, c, d, e);
                    }
                    if (f.isStacked) {
                        f.lf((g) => {
                            if (this.qw(g)) {
                                this.uv(g, c, d, e);
                            }
                            return true;
                        });
                    }
                }
            }
        }
        qw(a) {
            if (!super.qw(a)) {
                return false;
            }
            if (this.t4 != null) {
                if (a.dx) {
                    let b = a.ju();
                    if (!Base.equalsStatic(this.t4, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.t4, a.name)) {
                        return false;
                    }
                }
            }
            let c = this.ry(a);
            if (!c.c) {
                return false;
            }
            return true;
        }
        lx() {
            super.lx();
            if (!this.at.c && !this.cw()) {
                return;
            }
            if (this.cw()) {
                this.uw(this.qr, false);
            }
            else {
                this.uw(this.qp, false);
            }
        }
        qg() {
            return 1;
        }
        q3() {
            return 0.1;
        }
        q6() {
            return -0.4;
        }
        q5() {
            return 0.5;
        }
        s2() {
            return this.qd == 3 ? this.vz() : null;
        }
        s3() {
            return this.qe == 3 ? this.vz() : null;
        }
        vz() {
            if (this.vy == null) {
                this.vy = new DoubleCollection();
                this.vy.add(DeviceUtils.g(5));
                this.vy.add(DeviceUtils.g(5));
            }
            return this.vy;
        }
        uv(a, b, c, d) {
            let e = this.ry(a);
            if (!e.c) {
                return;
            }
            let f = e.d;
            f = a.ps(f, c, d);
            let g = false;
            let h = this.o5;
            if (h == null) {
                h = this.o9;
            }
            if (h == null) {
                h = a.o5;
                g = true;
            }
            let i = false;
            let j = this.vs;
            if (j == null) {
                if (this.o9 != null) {
                    j = this.o9;
                }
                else {
                    j = a.o5;
                    i = true;
                }
            }
            let k = false;
            let l = this.vv;
            if (l == null) {
                if (this.o9 != null) {
                    l = this.o9;
                }
                else {
                    l = a.o5;
                    k = true;
                }
            }
            let m = h;
            let n = h;
            let o = j;
            let p = l;
            if (this.vq != null) {
                m = this.vq;
            }
            else if (g) {
                switch (this.qd) {
                    case 0:
                    case 1:
                        m = this.td.cb(m, this.q0);
                        break;
                    case 2:
                        m = this.td.cd(m, this.q0);
                        break;
                    case 4:
                        m = this.td.cc(m, this.q0);
                        break;
                }
            }
            if (this.vr != null) {
                n = this.vr;
            }
            else if (g) {
                switch (this.qe) {
                    case 0:
                    case 1:
                        n = this.td.cb(n, this.q2);
                        break;
                    case 2:
                        n = this.td.cd(n, this.q2);
                        break;
                    case 4:
                        n = this.td.cc(n, this.q2);
                        break;
                }
            }
            if (i) {
                switch (this.qe) {
                    case 1:
                        o = this.td.cb(o, this.q2);
                        break;
                    case 2:
                        o = this.td.cd(o, this.q2);
                        break;
                }
            }
            if (k) {
                switch (this.qd) {
                    case 1:
                        p = this.td.cb(p, this.q0);
                        break;
                    case 2:
                        p = this.td.cd(p, this.q0);
                        break;
                }
            }
            b.ae.add(m);
            b.ah.add(n);
            b.af.add(f.y);
            b.ag.add(f.x);
            if (this.th && !isNaN_(f.y)) {
                AxisAnnotationFrameManager.c(b, f, a, this.ce, this.getEffectiveViewport(), h, o, this.tm, this.vu, this.vt, this.v0, this.tr, p, this.ts, this.vx, this.vw, this.v1, this.tx, this.v3 == 0, this.v2 == 0);
            }
        }
        uw(a, b) {
            let c = false;
            if (this.tk == null) {
                c = true;
                this.tl = new List$1(Axis.$, 0);
                this.tk = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
            }
            AxisAnnotationFrameManager.d(this, a, c, this.tk, this.tl, b, this.ty, this.tz, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
        }
        uu(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.fy;
            f.ai = e ? this.s1 : this.s0;
            f.am = this.pl;
            f.al = this.pk;
            f.ak = this.pk;
            f.aj = this.pj;
            f.ac = this.gw;
            return new Tuple$2(Path.$, Number_$type, f, b);
        }
        r8(a, b) {
            super.r8(a, b);
            let c = this.td.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.v3 == 0;
            let l = this.v2 == 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.uu(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.uu(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.cw()) {
                this.uw(this.qr, true);
            }
            else {
                this.uw(this.qp, false);
            }
        }
        ep() {
            return true;
        }
        l9(a, b, c, d) {
            super.l9(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (d == null) {
                        if (this.tk != null && this.tk.count > 0) {
                            let e;
                            if (this.cw()) {
                                e = this.qr;
                            }
                            else {
                                e = this.qp;
                            }
                            AxisAnnotationFrameManager.b(e);
                            AxisAnnotationFrameManager.d(this, e, true, this.tk, this.tl, true, this.ty, this.tz, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                        }
                    }
                    break;
                case CrosshairLayer.$$p[1]:
                    this.mn(true);
                    break;
                case CrosshairLayer.$$p[8]:
                    this.mn(true);
                    break;
                case CrosshairLayer.$$p[4]:
                case CrosshairLayer.$$p[5]:
                    this.mn(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.mn(true);
                    break;
            }
        }
    }
    CrosshairLayer.$t = markType(CrosshairLayer, 'CrosshairLayer', AnnotationLayer.$);
    CrosshairLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CrosshairLayer, 'raisePropertyChanged', ['HorizontalLineStroke:vq:ux', [Brush.$, null], 'HorizontalLineVisibility:v2:uy', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:th:uz', [0, false], 'SkipUnknownValues:ti:u0', [0, true], 'TargetSeriesName:t4:u1', [2, null], 'TargetSeries:te:u2', [Series.$, null], 'UseInterpolation:tj:u3', [0, true], 'VerticalLineStroke:vr:u4', [Brush.$, null], 'VerticalLineVisibility:v3:u5', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:tm:u6', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:vs:u7', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:ty:u8', [1, -1], 'XAxisAnnotationOutline:vt:u9', [Brush.$, null], 'XAxisAnnotationPaddingBottom:tn:va', [1, NaN], 'XAxisAnnotationPaddingLeft:to:vb', [1, NaN], 'XAxisAnnotationPaddingRight:tp:vc', [1, NaN], 'XAxisAnnotationPaddingTop:tq:vd', [1, NaN], 'XAxisAnnotationStrokeThickness:tr:ve', [1, NaN], 'XAxisAnnotationTextColor:vu:vf', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:ts:vg', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:vv:vh', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:tz:vi', [1, -1], 'YAxisAnnotationOutline:vw:vj', [Brush.$, null], 'YAxisAnnotationPaddingBottom:tt:vk', [1, NaN], 'YAxisAnnotationPaddingLeft:tu:vl', [1, NaN], 'YAxisAnnotationPaddingRight:tv:vm', [1, NaN], 'YAxisAnnotationPaddingTop:tw:vn', [1, NaN], 'YAxisAnnotationStrokeThickness:tx:vo', [1, NaN], 'YAxisAnnotationTextColor:vx:vp', [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.ce);
                $ret.activate = runOn(this, this.b7);
                $ret.disactivate = runOn(this, this.b9);
                $ret.destroy = runOn(this, this.b8);
                return $ret;
            })());
            this.b4.g4 = Defaults.j;
        }
        ce() {
            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.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;
            }
        }
        cb(a, b) {
            if (a == null) {
                return a;
            }
            return BrushUtil.l(a, b);
        }
        cd(a, b) {
            if (a == null) {
                return a;
            }
            return BrushUtil.n(a, b);
        }
        cc(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;
        }
        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.t(d);
                    }
                }
            }
        }
        al(a) {
            super.al(a);
            for (let b = 0; b < this.b6.count; b++) {
                this.e.a9.exportPathData(a, this.b6._inner[b], "crosshairLine", ["Main", "Crosshair"]);
            }
        }
    }
    CrosshairLayerView.$t = markType(CrosshairLayerView, 'CrosshairLayerView', AnnotationLayerView.$);
    return CrosshairLayerView;
})();
