/*
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 * as tslib_1 from "tslib";
import { AnnotationLayer } from "./AnnotationLayer";
import { Brush } from "igniteui-react-core/ES5/Brush";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { Series } from "./Series";
import { Visibility_$type } from "igniteui-react-core/ES5/Visibility";
import { CrosshairLayerFrame } from "./CrosshairLayerFrame";
import { List$1 } from "igniteui-react-core/ES5/List$1";
import { Axis } from "./Axis";
import { Dictionary$2 } from "igniteui-react-core/ES5/Dictionary$2";
import { Pool$1 } from "igniteui-react-core/ES5/Pool$1";
import { AxisAnnotation } from "./AxisAnnotation";
import { Type, Number_$type, enumGetBox, fromEnum, Point_$type, markType, runOn } from "igniteui-react-core/ES5/type";
import { AxisAnnotationFrameManager } from "./AxisAnnotationFrameManager";
import { Tuple$2 } from "igniteui-react-core/ES5/Tuple$2";
import { Path } from "igniteui-react-core/ES5/Path";
import { PathGeometry } from "igniteui-react-core/ES5/PathGeometry";
import { PathFigure } from "igniteui-react-core/ES5/PathFigure";
import { LineSegment } from "igniteui-react-core/ES5/LineSegment";
import { PropertyMetadata } from "igniteui-react-core/ES5/PropertyMetadata";
import { isNaN_ } from "igniteui-react-core/ES5/number";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { TranslateTransform } from "igniteui-react-core/ES5/TranslateTransform";
import { LineGeometry } from "igniteui-react-core/ES5/LineGeometry";
import { BrushUtil } from "igniteui-react-core/ES5/BrushUtil";
var CrosshairLayer = /** @class */ (function (_super) {
    tslib_1.__extends(CrosshairLayer, _super);
    function CrosshairLayer() {
        var _this = _super.call(this) || this;
        _this.mw = null;
        _this.mv = null;
        var a = new CrosshairLayerFrame();
        var b = new CrosshairLayerFrame();
        var c = new CrosshairLayerFrame();
        var d = _this.fc / 1000;
        _this.lq = a;
        _this.lp = b;
        _this.lr = c;
        _this.ab = CrosshairLayer.$;
        return _this;
    }
    CrosshairLayer.prototype.bf = function () {
        return new CrosshairLayerView(this);
    };
    CrosshairLayer.prototype.ii = function (a) {
        _super.prototype.ii.call(this, a);
        this.mq = a;
    };
    CrosshairLayer.prototype.l7 = function (a, b) {
        if (this.mr == null || this.mr == a) {
            if (!this.aq.c) {
                this.i1(b);
            }
        }
    };
    CrosshairLayer.prototype.l9 = function (a, b) {
        _super.prototype.l9.call(this, a, b);
        var c = a;
        var d = this.mu;
        var 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 {
            try {
                for (var _a = tslib_1.__values(fromEnum(this.bs.series)), _b = _a.next(); !_b.done; _b = _a.next()) {
                    var f = _b.value;
                    if (this.lu(f)) {
                        this.no(f, c, d, e);
                    }
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
                }
                finally { if (e_1) throw e_1.error; }
            }
        }
        var e_1, _c;
    };
    CrosshairLayer.prototype.lu = function (a) {
        if (!_super.prototype.lu.call(this, a)) {
            return false;
        }
        var b = this.l2(a);
        if (!b.a) {
            return false;
        }
        return true;
    };
    CrosshairLayer.prototype.ib = function () {
        _super.prototype.ib.call(this);
        if (!this.aq.c && !this.ca()) {
            return;
        }
        if (this.ca()) {
            this.np(this.lr, false);
        }
        else {
            this.np(this.lp, false);
        }
    };
    CrosshairLayer.prototype.no = function (a, b, c, d) {
        var e = this.l2(a);
        if (!e.a) {
            return;
        }
        var f = e.b;
        f = a.k9(f, c, d);
        var g = this.kr;
        if (g == null) {
            g = this.kt;
        }
        if (g == null) {
            g = a.kr;
            if (g != null) {
                g = this.mq.b6(g);
            }
        }
        var h = g;
        var 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);
        }
    };
    CrosshairLayer.prototype.np = function (a, b) {
        var 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);
    };
    CrosshairLayer.prototype.nn = function (a, b, c, d, e) {
        var 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);
    };
    CrosshairLayer.prototype.mc = function (a, b) {
        _super.prototype.mc.call(this, a, b);
        var c = this.mq.b0;
        var d = a;
        var e = d.x.count;
        var f = 0;
        var g = b.bp.left;
        var h = b.bp.right;
        var i = b.bp.top;
        var j = b.bp.bottom;
        var k = this.oj == 0;
        var l = this.oi == 0;
        for (var m = 0; m < e; m++) {
            var n = Math.floor(d.x._inner[m]);
            var o = Math.floor(d.y._inner[m]);
            var p = null;
            if (k) {
                if (isNaN_(n)) {
                    continue;
                }
                var q = this.nn(c, f, m, d, true);
                p = q.a;
                f = q.b;
                var r = new PathGeometry();
                var s = new PathFigure();
                s._startPoint = { $type: Point_$type, x: o, y: i };
                var 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;
                }
                var u = this.nn(c, f, m, d, false);
                p = u.a;
                f = u.b;
                var v = new PathGeometry();
                var w = new PathFigure();
                w._startPoint = { $type: Point_$type, x: g, y: n };
                var 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);
        }
    };
    CrosshairLayer.prototype.c5 = function () {
        return true;
    };
    CrosshairLayer.prototype.io = function (a, b, c, d) {
        _super.prototype.io.call(this, 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.$);
    return CrosshairLayer;
}(AnnotationLayer));
export { CrosshairLayer };
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]]);
var CrosshairLayerView = /** @class */ (function (_super) {
    tslib_1.__extends(CrosshairLayerView, _super);
    function CrosshairLayerView(a) {
        var _this = _super.call(this, a) || this;
        _this.bz = null;
        _this.b0 = null;
        _this.b1 = null;
        _this.bz = a;
        _this.b1 = new List$1(Path.$, 0);
        return _this;
    }
    CrosshairLayerView.prototype.ap = function () {
        var _this = this;
        _super.prototype.ap.call(this);
        this.b0 = ((function () {
            var $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;
        })());
    };
    CrosshairLayerView.prototype.b7 = function () {
        var a = new Path();
        a.j = new TranslateTransform();
        this.b1.add(a);
        return a;
    };
    CrosshairLayerView.prototype.b2 = function (a) {
        a._visibility = 0;
    };
    CrosshairLayerView.prototype.b4 = function (a) {
        a._visibility = 1;
    };
    CrosshairLayerView.prototype.b3 = function (a) {
        this.b1.remove(a);
    };
    CrosshairLayerView.prototype.b5 = function (a, b, c, d) {
        if (a.aj == null || a.aj.b.x != d || a.aj.c.x != c) {
            var e = ((function () {
                var $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;
        }
    };
    CrosshairLayerView.prototype.b6 = function (a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.h(a, 0.1);
    };
    CrosshairLayerView.prototype.a3 = function (a, b) {
        _super.prototype.a3.call(this, a, b);
        if (a.d && !b) {
            for (var c = 0; c < this.b1.count; c++) {
                var d = this.b1._inner[c];
                if (d._visibility == 0) {
                    a.s(d);
                }
            }
        }
    };
    CrosshairLayerView.prototype.ai = function (a) {
        _super.prototype.ai.call(this, a);
        for (var 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.$);
    return CrosshairLayerView;
}(AnnotationLayerView));
export { CrosshairLayerView };
/*<BeginStatics Name="Infragistics.Controls.Charts.CrosshairLayer" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.CrosshairLayer" />*/
