/*
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 { __extends, __values } from "tslib";
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 { AnnotationLayerView } from "./AnnotationLayerView";
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_ } from "igniteui-angular-core";
import { Defaults } from "./Defaults";
import { TranslateTransform } from "igniteui-angular-core";
import { LineGeometry } from "igniteui-angular-core";
/**
 * @hidden
 */
var CrosshairLayer = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CrosshairLayer, _super);
    function CrosshairLayer() {
        var _this = _super.call(this) || this;
        _this.xAxisAnnotationFormatLabel = null;
        _this.yAxisAnnotationFormatLabel = null;
        _this.ac8 = null;
        _this.aar = null;
        _this.aaq = null;
        var a = new CrosshairLayerFrame();
        var b = new CrosshairLayerFrame();
        var c = new CrosshairLayerFrame();
        var d = _this.kh / 1000;
        _this.xm = a;
        _this.xl = b;
        _this.xn = c;
        _this.ab = CrosshairLayer.$;
        return _this;
    }
    CrosshairLayer.prototype.bk = function () {
        return new CrosshairLayer();
    };
    CrosshairLayer.prototype.get_et = function () {
        return true;
    };
    CrosshairLayer.prototype.get_er = function () {
        return true;
    };
    CrosshairLayer.prototype.ct = function () {
        return new CrosshairLayerView(this);
    };
    CrosshairLayer.prototype.q7 = function (a) {
        _super.prototype.q7.call(this, a);
        this.aah = a;
    };
    CrosshairLayer.prototype.gv = function (a) {
        if (this.aai == null) {
            return true;
        }
        if (this.aai == a) {
            return true;
        }
        return false;
    };
    CrosshairLayer.prototype.aaj = function () {
        return this.xAxisAnnotationFormatLabel != null;
    };
    CrosshairLayer.prototype.aak = function () {
        return this.yAxisAnnotationFormatLabel != null;
    };
    Object.defineProperty(CrosshairLayer.prototype, "ada", {
        get: function () {
            return new Thickness(1, this.aau, this.aaw, this.aav, this.aat);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CrosshairLayer.prototype, "adb", {
        get: function () {
            return new Thickness(1, this.aa0, this.aa2, this.aa1, this.aaz);
        },
        enumerable: false,
        configurable: true
    });
    CrosshairLayer.prototype.y1 = function (a, b) {
        if (this.aai == null || this.aai == a) {
            if (!this.a1.c) {
                this.ry(b);
            }
        }
    };
    CrosshairLayer.prototype.y3 = function (a, b) {
        var e_1, _a;
        var _this = this;
        _super.prototype.y3.call(this, a, b);
        var c = a;
        var d = this.aap;
        var e = this.aao;
        c.af.clear();
        c.ag.clear();
        c.ae.clear();
        c.ah.clear();
        AxisAnnotationFrameManager.b(c);
        if (this.xs(this.aai)) {
            this.ab3(this.aai, c, d, e);
        }
        else {
            try {
                for (var _b = __values(fromEnum(this.dc.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var f = _c.value;
                    if (this.xs(f)) {
                        this.ab3(f, c, d, e);
                    }
                    if (f.isStacked) {
                        f.p9(function (g) {
                            if (_this.xs(g)) {
                                _this.ab3(g, c, d, e);
                            }
                            if (g.ei) {
                                g.p7(function (h) {
                                    if (_this.xs(h)) {
                                        _this.ab3(h, c, d, e);
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    if (f.ei) {
                        f.p7(function (g) {
                            if (_this.xs(g)) {
                                _this.ab3(g, c, d, e);
                            }
                            return true;
                        });
                    }
                }
            }
            catch (e_1_1) {
                e_1 = { error: e_1_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_1)
                        throw e_1.error;
                }
            }
        }
    };
    CrosshairLayer.prototype.xs = function (a) {
        if (!_super.prototype.xs.call(this, a)) {
            return false;
        }
        if (this.abc != null) {
            if (a.isFragment) {
                var b = a.nh();
                if (!Base.equalsStatic(this.abc, b)) {
                    return false;
                }
            }
            else {
                if (!Base.equalsStatic(this.abc, a.name)) {
                    return false;
                }
            }
        }
        var c = this.yw(a);
        if (!c.c) {
            return false;
        }
        return true;
    };
    CrosshairLayer.prototype.qv = function () {
        _super.prototype.qv.call(this);
        if (!this.a1.c && !this.d4()) {
            return;
        }
        if (this.d4()) {
            this.ab4(this.xn, false);
        }
        else {
            this.ab4(this.xl, false);
        }
    };
    CrosshairLayer.prototype.xc = function () {
        return 1;
    };
    CrosshairLayer.prototype.xz = function () {
        return 0.1;
    };
    CrosshairLayer.prototype.x2 = function () {
        return -0.4;
    };
    CrosshairLayer.prototype.x1 = function () {
        return 0.5;
    };
    CrosshairLayer.prototype.z4 = function () {
        return this.w9 == 3 ? this.ac9() : null;
    };
    CrosshairLayer.prototype.z5 = function () {
        return this.xa == 3 ? this.ac9() : null;
    };
    CrosshairLayer.prototype.ac9 = function () {
        if (this.ac8 == null) {
            this.ac8 = new DoubleCollection();
            this.ac8.add(DeviceUtils.g(5));
            this.ac8.add(DeviceUtils.g(5));
        }
        return this.ac8;
    };
    CrosshairLayer.prototype.ab3 = function (a, b, c, d) {
        var e = this.yw(a);
        if (!e.c) {
            return;
        }
        var f = e.d;
        var g = a.i8(f, c, d);
        if (this.aam && isNaN_(g)) {
            return;
        }
        if (this.aan && a.isFragment && g == 0) {
            return;
        }
        f = a.wm(f, c, d);
        var h = false;
        var i = this.vj;
        if (i == null) {
            i = this.vp;
        }
        if (i == null) {
            i = a.vj;
            h = true;
        }
        var j = false;
        var k = this.ac2;
        if (k == null) {
            if (this.vp != null) {
                k = this.vp;
            }
            else {
                k = a.vj;
                j = true;
            }
        }
        var l = false;
        var m = this.ac5;
        if (m == null) {
            if (this.vp != null) {
                m = this.vp;
            }
            else {
                m = a.vj;
                l = true;
            }
        }
        var n = i;
        var o = i;
        var p = k;
        var q = m;
        if (this.ac0 != null) {
            n = this.ac0;
        }
        else if (h) {
            switch (this.w9) {
                case 0:
                case 1:
                    n = this.aah.ck(n, this.xw);
                    break;
                case 2:
                    n = this.aah.cm(n, this.xw);
                    break;
                case 4:
                    n = this.aah.cl(n, this.xw);
                    break;
            }
        }
        if (this.ac1 != null) {
            o = this.ac1;
        }
        else if (h) {
            switch (this.xa) {
                case 0:
                case 1:
                    o = this.aah.ck(o, this.xy);
                    break;
                case 2:
                    o = this.aah.cm(o, this.xy);
                    break;
                case 4:
                    o = this.aah.cl(o, this.xy);
                    break;
            }
        }
        if (j) {
            switch (this.xa) {
                case 1:
                    p = this.aah.ck(p, this.xy);
                    break;
                case 2:
                    p = this.aah.cm(p, this.xy);
                    break;
            }
        }
        if (l) {
            switch (this.w9) {
                case 1:
                    q = this.aah.ck(q, this.xw);
                    break;
                case 2:
                    q = this.aah.cm(q, this.xw);
                    break;
            }
        }
        b.ae.add(n);
        b.ah.add(o);
        b.af.add(f.y);
        b.ag.add(f.x);
        if (this.aal && !isNaN_(f.y)) {
            AxisAnnotationFrameManager.c(b, f, a, this.dc, this.getEffectiveViewport(), i, p, this.aas, this.ac4, this.ac3, this.ada, this.aax, q, this.aay, this.ac7, this.ac6, this.adb, this.aa3, this.add == 0, this.adc == 0);
        }
    };
    CrosshairLayer.prototype.ab4 = function (a, b) {
        var c = false;
        if (this.aaq == null) {
            c = true;
            this.aar = new List$1(Axis.$, 0);
            this.aaq = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
        }
        AxisAnnotationFrameManager.d(this, a, c, this.aaq, this.aar, b, this.aa4, this.aa5, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
    };
    CrosshairLayer.prototype.ab2 = function (a, b, c, d, e) {
        var 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.ig;
        f.ai = e ? this.z2 : this.z1;
        f.am = this.wf;
        f.al = this.we;
        f.ak = this.we;
        f.aj = this.wd;
        f.ac = this.jk;
        return new Tuple$2(Path.$, Number_$type, f, b);
    };
    CrosshairLayer.prototype.y6 = function (a, b) {
        _super.prototype.y6.call(this, a, b);
        var c = this.aah.co;
        var d = a;
        var e = d.af.count;
        var f = 0;
        var g = b.b9.left;
        var h = b.b9.right;
        var i = b.b9.top;
        var j = b.b9.bottom;
        var k = this.add == 0;
        var l = this.adc == 0;
        for (var m = 0; m < e; m++) {
            var n = Math.floor(d.af._inner[m]);
            var o = Math.floor(d.ag._inner[m]);
            var p = null;
            if (k) {
                if (isNaN_(n)) {
                    continue;
                }
                var q = this.ab2(c, f, m, d, true);
                p = q.c;
                f = q.d;
                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.c.add(s);
                p.an = r;
            }
            if (l) {
                if (isNaN_(n)) {
                    continue;
                }
                var u = this.ab2(c, f, m, d, false);
                p = u.c;
                f = u.d;
                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.c.add(w);
                p.an = v;
            }
        }
        c.count = f;
        if (this.d4()) {
            this.ab4(this.xn, true);
        }
        else {
            this.ab4(this.xl, false);
        }
    };
    CrosshairLayer.prototype.gb = function () {
        return true;
    };
    CrosshairLayer.prototype.rg = function (a, b, c, d) {
        _super.prototype.rg.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (d == null) {
                    if (this.aaq != null && this.aaq.count > 0) {
                        var e = void 0;
                        if (this.d4()) {
                            e = this.xn;
                        }
                        else {
                            e = this.xl;
                        }
                        AxisAnnotationFrameManager.b(e);
                        AxisAnnotationFrameManager.d(this, e, true, this.aaq, this.aar, true, this.aa4, this.aa5, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                    }
                }
                break;
            case CrosshairLayer.$$p[1]:
                this.ry(true);
                break;
            case CrosshairLayer.$$p[10]:
                this.ry(true);
                break;
            case CrosshairLayer.$$p[6]:
            case CrosshairLayer.$$p[7]:
                this.ry(true);
                break;
            case CrosshairLayer.$$p[2]:
            case CrosshairLayer.$$p[12]:
            case CrosshairLayer.$$p[11]:
            case CrosshairLayer.$$p[14]:
            case CrosshairLayer.$$p[16]:
            case CrosshairLayer.$$p[18]:
            case CrosshairLayer.$$p[17]:
            case CrosshairLayer.$$p[15]:
            case CrosshairLayer.$$p[19]:
            case CrosshairLayer.$$p[20]:
            case CrosshairLayer.$$p[22]:
            case CrosshairLayer.$$p[24]:
            case CrosshairLayer.$$p[26]:
            case CrosshairLayer.$$p[28]:
            case CrosshairLayer.$$p[27]:
            case CrosshairLayer.$$p[25]:
            case CrosshairLayer.$$p[29]:
            case CrosshairLayer.$$p[30]:
            case CrosshairLayer.$$p[0]:
            case CrosshairLayer.$$p[9]:
            case CrosshairLayer.$$p[8]:
                this.ry(true);
                break;
        }
    };
    CrosshairLayer.$t = markType(CrosshairLayer, 'CrosshairLayer', AnnotationLayer.$);
    CrosshairLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CrosshairLayer, 'raisePropertyChanged', ['HorizontalLineStroke:ac0:ab5', [Brush.$, null], 'HorizontalLineVisibility:adc:ab6', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:aal:ab7', [0, false], 'SkipAxisAnnotationOnInvalidData:aam:ab8', [0, false], 'SkipAxisAnnotationOnZeroValueFragments:aan:ab9', [0, false], 'SkipUnknownValues:aao:aca', [0, true], 'TargetSeriesName:abc:acb', [2, null], 'TargetSeries:aai:acc', [Series.$, null], 'UseInterpolation:aap:acd', [0, true], 'VerticalLineStroke:ac1:ace', [Brush.$, null], 'VerticalLineVisibility:add:acf', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:aas:acg', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:ac2:ach', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:aa4:aci', [1, -1], 'XAxisAnnotationOutline:ac3:acj', [Brush.$, null], 'XAxisAnnotationPaddingBottom:aat:ack', [1, NaN], 'XAxisAnnotationPaddingLeft:aau:acl', [1, NaN], 'XAxisAnnotationPaddingRight:aav:acm', [1, NaN], 'XAxisAnnotationPaddingTop:aaw:acn', [1, NaN], 'XAxisAnnotationStrokeThickness:aax:aco', [1, NaN], 'XAxisAnnotationTextColor:ac4:acp', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:aay:acq', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:ac5:acr', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:aa5:acs', [1, -1], 'YAxisAnnotationOutline:ac6:act', [Brush.$, null], 'YAxisAnnotationPaddingBottom:aaz:acu', [1, NaN], 'YAxisAnnotationPaddingLeft:aa0:acv', [1, NaN], 'YAxisAnnotationPaddingRight:aa1:acw', [1, NaN], 'YAxisAnnotationPaddingTop:aa2:acx', [1, NaN], 'YAxisAnnotationStrokeThickness:aa3:acy', [1, NaN], 'YAxisAnnotationTextColor:ac7:acz', [Brush.$, null]]);
    return CrosshairLayer;
}(AnnotationLayer));
export { CrosshairLayer };
/**
 * @hidden
 */
var CrosshairLayerView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CrosshairLayerView, _super);
    function CrosshairLayerView(a) {
        var _this = _super.call(this, a) || this;
        _this.cn = null;
        _this.co = null;
        _this.cp = null;
        _this.cn = a;
        _this.cp = new List$1(Path.$, 0);
        return _this;
    }
    CrosshairLayerView.prototype.a4 = function () {
        var _this = this;
        _super.prototype.a4.call(this);
        this.co = ((function () {
            var $ret = new Pool$1(Path.$);
            $ret.create = runOn(_this, _this.cu);
            $ret.activate = runOn(_this, _this.cq);
            $ret.disactivate = runOn(_this, _this.cs);
            $ret.destroy = runOn(_this, _this.cr);
            return $ret;
        })());
        this.cn.jt = Defaults.crosshairLineThickness;
    };
    CrosshairLayerView.prototype.cu = function () {
        var a = new Path();
        a.j = new TranslateTransform();
        this.cp.add(a);
        return a;
    };
    CrosshairLayerView.prototype.cq = function (a) {
        a._visibility = 0;
    };
    CrosshairLayerView.prototype.cs = function (a) {
        a._visibility = 1;
    };
    CrosshairLayerView.prototype.cr = function (a) {
        this.cp.remove(a);
    };
    CrosshairLayerView.prototype.ct = function (a, b, c, d) {
        if (a.an == null || a.an.c.x != d || a.an.d.x != c) {
            var e = ((function () {
                var $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;
        }
    };
    CrosshairLayerView.prototype.bj = function (a, b) {
        _super.prototype.bj.call(this, a, b);
        if (a.d && !b) {
            for (var c = 0; c < this.cp.count; c++) {
                var d = this.cp._inner[c];
                if (d._visibility == 0) {
                    a.t(d);
                }
            }
        }
    };
    CrosshairLayerView.prototype.ax = function (a) {
        _super.prototype.ax.call(this, a);
        for (var b = 0; b < this.cp.count; b++) {
            this.f.bc.exportPathData(a, this.cp._inner[b], "crosshairLine", ["Main", "Crosshair"]);
        }
    };
    CrosshairLayerView.$t = markType(CrosshairLayerView, 'CrosshairLayerView', AnnotationLayerView.$);
    return CrosshairLayerView;
}(AnnotationLayerView));
export { CrosshairLayerView };
