/*
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 { 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
 */
var CrosshairLayer = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CrosshairLayer, _super);
    function CrosshairLayer() {
        var _this = _super.call(this) || this;
        _this.xAxisAnnotationFormatLabel = null;
        _this.yAxisAnnotationFormatLabel = null;
        _this.rm = null;
        _this.rl = null;
        var a = new CrosshairLayerFrame();
        var b = new CrosshairLayerFrame();
        var c = new CrosshairLayerFrame();
        var d = _this.ho / 1000;
        _this.qa = a;
        _this.p9 = b;
        _this.qb = c;
        _this.ab = CrosshairLayer.$;
        return _this;
    }
    CrosshairLayer.prototype.get_db = function () {
        return true;
    };
    CrosshairLayer.prototype.get_c9 = function () {
        return true;
    };
    CrosshairLayer.prototype.bx = function () {
        return new CrosshairLayerView(this);
    };
    CrosshairLayer.prototype.l2 = function (a) {
        _super.prototype.l2.call(this, a);
        this.re = a;
    };
    CrosshairLayer.prototype.rg = function () {
        return this.xAxisAnnotationFormatLabel != null;
    };
    CrosshairLayer.prototype.rh = function () {
        return this.yAxisAnnotationFormatLabel != null;
    };
    Object.defineProperty(CrosshairLayer.prototype, "tz", {
        get: function () {
            return new Thickness(1, this.rp, this.rr, this.rq, this.ro);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CrosshairLayer.prototype, "t0", {
        get: function () {
            return new Thickness(1, this.rv, this.rx, this.rw, this.ru);
        },
        enumerable: false,
        configurable: true
    });
    CrosshairLayer.prototype.qt = function (a, b) {
        if (this.rf == null || this.rf == a) {
            if (!this.as.c) {
                this.ml(b);
            }
        }
    };
    CrosshairLayer.prototype.qv = function (a, b) {
        var e_1, _a;
        var _this = this;
        _super.prototype.qv.call(this, a, b);
        var c = a;
        var d = this.rk;
        var e = this.rj;
        c.af.clear();
        c.ag.clear();
        c.ae.clear();
        c.ah.clear();
        AxisAnnotationFrameManager.b(c);
        if (this.qg(this.rf)) {
            this.sw(this.rf, c, d, e);
        }
        else {
            try {
                for (var _b = __values(fromEnum(this.cd.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var f = _c.value;
                    if (this.qg(f)) {
                        this.sw(f, c, d, e);
                    }
                    if (f.isStacked) {
                        f.ld(function (g) {
                            if (_this.qg(g)) {
                                _this.sw(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.qg = function (a) {
        if (!_super.prototype.qg.call(this, a)) {
            return false;
        }
        if (this.r5 != null) {
            if (a.dv) {
                var b = a.jr();
                if (!Base.equalsStatic(this.r5, b)) {
                    return false;
                }
            }
            else {
                if (!Base.equalsStatic(this.r5, a.name)) {
                    return false;
                }
            }
        }
        var c = this.qo(a);
        if (!c.c) {
            return false;
        }
        return true;
    };
    CrosshairLayer.prototype.lv = function () {
        _super.prototype.lv.call(this);
        if (!this.as.c && !this.cv()) {
            return;
        }
        if (this.cv()) {
            this.sx(this.qb, false);
        }
        else {
            this.sx(this.p9, false);
        }
    };
    CrosshairLayer.prototype.sw = function (a, b, c, d) {
        var e = this.qo(a);
        if (!e.c) {
            return;
        }
        var f = e.d;
        f = a.pq(f, c, d);
        var g = this.o3;
        if (g == null) {
            g = this.o7;
        }
        if (g == null) {
            g = a.o3;
            if (g != null) {
                g = this.re.cb(g);
            }
        }
        var h = g;
        var i = g;
        if (this.tr != null) {
            h = this.tr;
        }
        if (this.ts != null) {
            i = this.ts;
        }
        b.ae.add(h);
        b.ah.add(i);
        b.af.add(f.y);
        b.ag.add(f.x);
        if (this.ri && !isNaN_(f.y)) {
            AxisAnnotationFrameManager.c(b, f, a, this.cd, this.getEffectiveViewport(), g, this.tt, this.rn, this.tv, this.tu, this.tz, this.rs, this.tw, this.rt, this.ty, this.tx, this.t0, this.ry, this.t2 == 0, this.t1 == 0);
        }
    };
    CrosshairLayer.prototype.sx = function (a, b) {
        var c = false;
        if (this.rl == null) {
            c = true;
            this.rm = new List$1(Axis.$, 0);
            this.rl = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
        }
        AxisAnnotationFrameManager.d(this, a, c, this.rl, this.rm, b, this.rz, this.r0, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
    };
    CrosshairLayer.prototype.sv = 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.ac = this.fw;
        f.ai = this.pg;
        f.ad = this.ph;
        return new Tuple$2(Path.$, Number_$type, f, b);
    };
    CrosshairLayer.prototype.qy = function (a, b) {
        _super.prototype.qy.call(this, a, b);
        var c = this.re.b5;
        var d = a;
        var e = d.af.count;
        var f = 0;
        var g = b.bu.left;
        var h = b.bu.right;
        var i = b.bu.top;
        var j = b.bu.bottom;
        var k = this.t2 == 0;
        var l = this.t1 == 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.sv(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.ak = r;
            }
            if (l) {
                if (isNaN_(n)) {
                    continue;
                }
                var u = this.sv(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.ak = v;
            }
        }
        c.count = f;
        if (this.cv()) {
            this.sx(this.qb, true);
        }
        else {
            this.sx(this.p9, false);
        }
    };
    CrosshairLayer.prototype.en = function () {
        return true;
    };
    CrosshairLayer.prototype.l7 = function (a, b, c, d) {
        _super.prototype.l7.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (d == null) {
                    if (this.rl != null && this.rl.count > 0) {
                        var e = void 0;
                        if (this.cv()) {
                            e = this.qb;
                        }
                        else {
                            e = this.p9;
                        }
                        AxisAnnotationFrameManager.b(e);
                        AxisAnnotationFrameManager.d(this, e, true, this.rl, this.rm, true, this.rz, this.r0, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                    }
                }
                break;
            case CrosshairLayer.$$p[1]:
                this.ml(true);
                break;
            case CrosshairLayer.$$p[8]:
                this.ml(true);
                break;
            case CrosshairLayer.$$p[4]:
            case CrosshairLayer.$$p[5]:
                this.ml(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.ml(true);
                break;
        }
    };
    CrosshairLayer.$t = markType(CrosshairLayer, 'CrosshairLayer', AnnotationLayer.$);
    CrosshairLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CrosshairLayer, 'raisePropertyChanged', ['HorizontalLineStroke:tr:sy', [Brush.$, null], 'HorizontalLineVisibility:t1:sz', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:ri:s0', [0, false], 'SkipUnknownValues:rj:s1', [0, true], 'TargetSeriesName:r5:s2', [2, null], 'TargetSeries:rf:s3', [Series.$, null], 'UseInterpolation:rk:s4', [0, true], 'VerticalLineStroke:ts:s5', [Brush.$, null], 'VerticalLineVisibility:t2:s6', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:rn:s7', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:tt:s8', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:rz:s9', [1, -1], 'XAxisAnnotationOutline:tu:ta', [Brush.$, null], 'XAxisAnnotationPaddingBottom:ro:tb', [1, NaN], 'XAxisAnnotationPaddingLeft:rp:tc', [1, NaN], 'XAxisAnnotationPaddingRight:rq:td', [1, NaN], 'XAxisAnnotationPaddingTop:rr:te', [1, NaN], 'XAxisAnnotationStrokeThickness:rs:tf', [1, NaN], 'XAxisAnnotationTextColor:tv:tg', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:rt:th', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:tw:ti', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:r0:tj', [1, -1], 'YAxisAnnotationOutline:tx:tk', [Brush.$, null], 'YAxisAnnotationPaddingBottom:ru:tl', [1, NaN], 'YAxisAnnotationPaddingLeft:rv:tm', [1, NaN], 'YAxisAnnotationPaddingRight:rw:tn', [1, NaN], 'YAxisAnnotationPaddingTop:rx:to', [1, NaN], 'YAxisAnnotationStrokeThickness:ry:tp', [1, NaN], 'YAxisAnnotationTextColor:ty:tq', [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.b4 = null;
        _this.b5 = null;
        _this.b6 = null;
        _this.b4 = a;
        _this.b6 = new List$1(Path.$, 0);
        return _this;
    }
    CrosshairLayerView.prototype.as = function () {
        var _this = this;
        _super.prototype.as.call(this);
        this.b5 = ((function () {
            var $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.g1 = Defaults.j;
    };
    CrosshairLayerView.prototype.cc = function () {
        var a = new Path();
        a.j = new TranslateTransform();
        this.b6.add(a);
        return a;
    };
    CrosshairLayerView.prototype.b7 = function (a) {
        a._visibility = 0;
    };
    CrosshairLayerView.prototype.b9 = function (a) {
        a._visibility = 1;
    };
    CrosshairLayerView.prototype.b8 = function (a) {
        this.b6.remove(a);
    };
    CrosshairLayerView.prototype.ca = function (a, b, c, d) {
        if (a.ak == null || a.ak.c.x != d || a.ak.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.ak = e;
        }
    };
    CrosshairLayerView.prototype.cb = function (a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.l(a, 0.1);
    };
    CrosshairLayerView.prototype.a6 = function (a, b) {
        _super.prototype.a6.call(this, a, b);
        if (a.d && !b) {
            for (var c = 0; c < this.b6.count; c++) {
                var d = this.b6._inner[c];
                if (d._visibility == 0) {
                    a.t(d);
                }
            }
        }
    };
    CrosshairLayerView.prototype.al = function (a) {
        _super.prototype.al.call(this, a);
        for (var 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;
}(AnnotationLayerView));
export { CrosshairLayerView };
