/*
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/ES2015/Brush";
import { DependencyProperty } from "igniteui-react-core/ES2015/DependencyProperty";
import { Series } from "./Series";
import { Visibility_$type } from "igniteui-react-core/ES2015/Visibility";
import { CrosshairLayerFrame } from "./CrosshairLayerFrame";
import { List$1 } from "igniteui-react-core/ES2015/List$1";
import { Axis } from "./Axis";
import { Dictionary$2 } from "igniteui-react-core/ES2015/Dictionary$2";
import { Pool$1 } from "igniteui-react-core/ES2015/Pool$1";
import { AxisAnnotation } from "./AxisAnnotation";
import { Type, Number_$type, enumGetBox, fromEnum, Point_$type, markType, runOn } from "igniteui-react-core/ES2015/type";
import { AxisAnnotationFrameManager } from "./AxisAnnotationFrameManager";
import { Tuple$2 } from "igniteui-react-core/ES2015/Tuple$2";
import { Path } from "igniteui-react-core/ES2015/Path";
import { PathGeometry } from "igniteui-react-core/ES2015/PathGeometry";
import { PathFigure } from "igniteui-react-core/ES2015/PathFigure";
import { LineSegment } from "igniteui-react-core/ES2015/LineSegment";
import { PropertyMetadata } from "igniteui-react-core/ES2015/PropertyMetadata";
import { isNaN_ } from "igniteui-react-core/ES2015/number";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { TranslateTransform } from "igniteui-react-core/ES2015/TranslateTransform";
import { LineGeometry } from "igniteui-react-core/ES2015/LineGeometry";
import { BrushUtil } from "igniteui-react-core/ES2015/BrushUtil";
export class CrosshairLayer extends AnnotationLayer {
    constructor() {
        super();
        this.mw = null;
        this.mv = null;
        let a = new CrosshairLayerFrame();
        let b = new CrosshairLayerFrame();
        let c = new CrosshairLayerFrame();
        let d = this.fc / 1000;
        this.lq = a;
        this.lp = b;
        this.lr = c;
        this.ab = CrosshairLayer.$;
    }
    bf() {
        return new CrosshairLayerView(this);
    }
    ii(a) {
        super.ii(a);
        this.mq = a;
    }
    l7(a, b) {
        if (this.mr == null || this.mr == a) {
            if (!this.aq.c) {
                this.i1(b);
            }
        }
    }
    l9(a, b) {
        super.l9(a, b);
        let c = a;
        let d = this.mu;
        let e = this.mt;
        c.x.clear();
        c.y.clear();
        c.w.clear();
        c.z.clear();
        AxisAnnotationFrameManager.b(c);
        if (this.lu(this.mr)) {
            this.no(this.mr, c, d, e);
        }
        else {
            for (let f of fromEnum(this.bs.series)) {
                if (this.lu(f)) {
                    this.no(f, c, d, e);
                }
            }
        }
    }
    lu(a) {
        if (!super.lu(a)) {
            return false;
        }
        let b = this.l2(a);
        if (!b.a) {
            return false;
        }
        return true;
    }
    ib() {
        super.ib();
        if (!this.aq.c && !this.ca()) {
            return;
        }
        if (this.ca()) {
            this.np(this.lr, false);
        }
        else {
            this.np(this.lp, false);
        }
    }
    no(a, b, c, d) {
        let e = this.l2(a);
        if (!e.a) {
            return;
        }
        let f = e.b;
        f = a.k9(f, c, d);
        let g = this.kr;
        if (g == null) {
            g = this.kt;
        }
        if (g == null) {
            g = a.kr;
            if (g != null) {
                g = this.mq.b6(g);
            }
        }
        let h = g;
        let i = g;
        if (this.oa != null) {
            h = this.oa;
        }
        if (this.ob != null) {
            i = this.ob;
        }
        b.w.add(h);
        b.z.add(i);
        b.x.add(f.y);
        b.y.add(f.x);
        if (this.ms) {
            AxisAnnotationFrameManager.c(b, f, a, this.bs, this.getEffectiveViewport(), g, this.oc, this.oe, this.od, this.mx, this.my, this.of, this.oh, this.og, this.mz, this.m0, this.oj == 0, this.oi == 0);
        }
    }
    np(a, b) {
        let c = false;
        if (this.mv == null) {
            c = true;
            this.mw = new List$1(Axis.$, 0);
            this.mv = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
        }
        AxisAnnotationFrameManager.d(a, c, this.mv, this.mw, b, this.m1, this.m2);
    }
    nn(a, b, c, d, e) {
        let f = a.item(b);
        b++;
        if (e) {
            f._stroke = d.z._inner[c];
            f._fill = d.z._inner[c];
        }
        else {
            f._stroke = d.w._inner[c];
            f._fill = d.w._inner[c];
        }
        f.ac = this.es;
        f.ai = this.kz;
        f.ad = this.k0;
        return new Tuple$2(Path.$, Number_$type, f, b);
    }
    mc(a, b) {
        super.mc(a, b);
        let c = this.mq.b0;
        let d = a;
        let e = d.x.count;
        let f = 0;
        let g = b.bp.left;
        let h = b.bp.right;
        let i = b.bp.top;
        let j = b.bp.bottom;
        let k = this.oj == 0;
        let l = this.oi == 0;
        for (let m = 0; m < e; m++) {
            let n = Math.floor(d.x._inner[m]);
            let o = Math.floor(d.y._inner[m]);
            let p = null;
            if (k) {
                if (isNaN_(n)) {
                    continue;
                }
                let q = this.nn(c, f, m, d, true);
                p = q.a;
                f = q.b;
                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.b.add(s);
                p.aj = r;
            }
            if (l) {
                if (isNaN_(n)) {
                    continue;
                }
                let u = this.nn(c, f, m, d, false);
                p = u.a;
                f = u.b;
                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.b.add(w);
                p.aj = v;
            }
        }
        c.count = f;
        if (this.ca()) {
            this.np(this.lr, true);
        }
        else {
            this.np(this.lp, false);
        }
    }
    c5() {
        return true;
    }
    io(a, b, c, d) {
        super.io(a, b, c, d);
        switch (b) {
            case CrosshairLayer.$$p[1]:
                this.i1(true);
                break;
            case CrosshairLayer.$$p[7]:
                this.i1(true);
                break;
            case CrosshairLayer.$$p[4]:
                this.i1(true);
                break;
            case CrosshairLayer.$$p[2]:
            case CrosshairLayer.$$p[8]:
            case CrosshairLayer.$$p[10]:
            case CrosshairLayer.$$p[11]:
            case CrosshairLayer.$$p[12]:
            case CrosshairLayer.$$p[13]:
            case CrosshairLayer.$$p[14]:
            case CrosshairLayer.$$p[16]:
            case CrosshairLayer.$$p[17]:
            case CrosshairLayer.$$p[18]:
            case CrosshairLayer.$$p[19]:
            case CrosshairLayer.$$p[0]:
            case CrosshairLayer.$$p[6]:
            case CrosshairLayer.$$p[5]:
                this.i1(true);
                break;
        }
    }
}
CrosshairLayer.$t = markType(CrosshairLayer, 'CrosshairLayer', AnnotationLayer.$);
Type.dep(DependencyProperty, PropertyMetadata, CrosshairLayer, 'raisePropertyChanged', ['HorizontalLineStroke:oa:nq', [Brush.$, null], 'HorizontalLineVisibility:oi:nr', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:ms:ns', [0, false], 'SkipUnknownValues:mt:nt', [0, true], 'TargetSeries:mr:nu', [Series.$, null], 'UseInterpolation:mu:nv', [0, true], 'VerticalLineStroke:ob:nw', [Brush.$, null], 'VerticalLineVisibility:oj:nx', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackground:oc:ny', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:m1:nz', [1, -1], 'XAxisAnnotationOutline:od:n0', [Brush.$, null], 'XAxisAnnotationPadding:mx:n1', [1, NaN], 'XAxisAnnotationStrokeThickness:my:n2', [1, NaN], 'XAxisAnnotationTextColor:oe:n3', [Brush.$, null], 'YAxisAnnotationBackground:of:n4', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:m2:n5', [1, -1], 'YAxisAnnotationOutline:og:n6', [Brush.$, null], 'YAxisAnnotationPadding:mz:n7', [1, NaN], 'YAxisAnnotationStrokeThickness:m0:n8', [1, NaN], 'YAxisAnnotationTextColor:oh:n9', [Brush.$, null]]);
export class CrosshairLayerView extends AnnotationLayerView {
    constructor(a) {
        super(a);
        this.bz = null;
        this.b0 = null;
        this.b1 = null;
        this.bz = a;
        this.b1 = new List$1(Path.$, 0);
    }
    ap() {
        super.ap();
        this.b0 = ((() => {
            let $ret = new Pool$1(Path.$);
            $ret.create = runOn(this, this.b7);
            $ret.activate = runOn(this, this.b2);
            $ret.disactivate = runOn(this, this.b4);
            $ret.destroy = runOn(this, this.b3);
            return $ret;
        })());
    }
    b7() {
        let a = new Path();
        a.j = new TranslateTransform();
        this.b1.add(a);
        return a;
    }
    b2(a) {
        a._visibility = 0;
    }
    b4(a) {
        a._visibility = 1;
    }
    b3(a) {
        this.b1.remove(a);
    }
    b5(a, b, c, d) {
        if (a.aj == null || a.aj.b.x != d || a.aj.c.x != c) {
            let e = ((() => {
                let $ret = new LineGeometry();
                $ret.c = { $type: Point_$type, x: c, y: b };
                $ret.b = { $type: Point_$type, x: d, y: b };
                return $ret;
            })());
            a.aj = e;
        }
    }
    b6(a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.h(a, 0.1);
    }
    a3(a, b) {
        super.a3(a, b);
        if (a.d && !b) {
            for (let c = 0; c < this.b1.count; c++) {
                let d = this.b1._inner[c];
                if (d._visibility == 0) {
                    a.s(d);
                }
            }
        }
    }
    ai(a) {
        super.ai(a);
        for (let b = 0; b < this.b1.count; b++) {
            this.e.a2.exportPathData(a, this.b1._inner[b], "crosshairLine", ["Main", "Crosshair"]);
        }
    }
}
CrosshairLayerView.$t = markType(CrosshairLayerView, 'CrosshairLayerView', AnnotationLayerView.$);
/*<BeginStatics Name="Infragistics.Controls.Charts.CrosshairLayer" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.CrosshairLayer" />*/
