/*
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 { 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
 */
var CrosshairLayer = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CrosshairLayer, _super);
    function CrosshairLayer() {
        var _this = _super.call(this) || this;
        _this.xAxisAnnotationFormatLabel = null;
        _this.yAxisAnnotationFormatLabel = null;
        _this.vy = null;
        _this.tl = null;
        _this.tk = null;
        var a = new CrosshairLayerFrame();
        var b = new CrosshairLayerFrame();
        var c = new CrosshairLayerFrame();
        var d = _this.hr / 1000;
        _this.qq = a;
        _this.qp = b;
        _this.qr = c;
        _this.ab = CrosshairLayer.$;
        return _this;
    }
    CrosshairLayer.prototype.get_dc = function () {
        return true;
    };
    CrosshairLayer.prototype.get_da = function () {
        return true;
    };
    CrosshairLayer.prototype.by = function () {
        return new CrosshairLayerView(this);
    };
    CrosshairLayer.prototype.l4 = function (a) {
        _super.prototype.l4.call(this, a);
        this.td = a;
    };
    CrosshairLayer.prototype.tf = function () {
        return this.xAxisAnnotationFormatLabel != null;
    };
    CrosshairLayer.prototype.tg = function () {
        return this.yAxisAnnotationFormatLabel != null;
    };
    Object.defineProperty(CrosshairLayer.prototype, "v0", {
        get: function () {
            return new Thickness(1, this.to, this.tq, this.tp, this.tn);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CrosshairLayer.prototype, "v1", {
        get: function () {
            return new Thickness(1, this.tu, this.tw, this.tv, this.tt);
        },
        enumerable: false,
        configurable: true
    });
    CrosshairLayer.prototype.r3 = function (a, b) {
        if (this.te == null || this.te == a) {
            if (!this.at.c) {
                this.mn(b);
            }
        }
    };
    CrosshairLayer.prototype.r5 = function (a, b) {
        var e_1, _a;
        var _this = this;
        _super.prototype.r5.call(this, a, b);
        var c = a;
        var d = this.tj;
        var 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 {
            try {
                for (var _b = __values(fromEnum(this.ce.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var f = _c.value;
                    if (this.qw(f)) {
                        this.uv(f, c, d, e);
                    }
                    if (f.isStacked) {
                        f.lf(function (g) {
                            if (_this.qw(g)) {
                                _this.uv(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.qw = function (a) {
        if (!_super.prototype.qw.call(this, a)) {
            return false;
        }
        if (this.t4 != null) {
            if (a.dx) {
                var b = a.ju();
                if (!Base.equalsStatic(this.t4, b)) {
                    return false;
                }
            }
            else {
                if (!Base.equalsStatic(this.t4, a.name)) {
                    return false;
                }
            }
        }
        var c = this.ry(a);
        if (!c.c) {
            return false;
        }
        return true;
    };
    CrosshairLayer.prototype.lx = function () {
        _super.prototype.lx.call(this);
        if (!this.at.c && !this.cw()) {
            return;
        }
        if (this.cw()) {
            this.uw(this.qr, false);
        }
        else {
            this.uw(this.qp, false);
        }
    };
    CrosshairLayer.prototype.qg = function () {
        return 1;
    };
    CrosshairLayer.prototype.q3 = function () {
        return 0.1;
    };
    CrosshairLayer.prototype.q6 = function () {
        return -0.4;
    };
    CrosshairLayer.prototype.q5 = function () {
        return 0.5;
    };
    CrosshairLayer.prototype.s2 = function () {
        return this.qd == 3 ? this.vz() : null;
    };
    CrosshairLayer.prototype.s3 = function () {
        return this.qe == 3 ? this.vz() : null;
    };
    CrosshairLayer.prototype.vz = function () {
        if (this.vy == null) {
            this.vy = new DoubleCollection();
            this.vy.add(DeviceUtils.g(5));
            this.vy.add(DeviceUtils.g(5));
        }
        return this.vy;
    };
    CrosshairLayer.prototype.uv = function (a, b, c, d) {
        var e = this.ry(a);
        if (!e.c) {
            return;
        }
        var f = e.d;
        f = a.ps(f, c, d);
        var g = false;
        var h = this.o5;
        if (h == null) {
            h = this.o9;
        }
        if (h == null) {
            h = a.o5;
            g = true;
        }
        var i = false;
        var j = this.vs;
        if (j == null) {
            if (this.o9 != null) {
                j = this.o9;
            }
            else {
                j = a.o5;
                i = true;
            }
        }
        var k = false;
        var l = this.vv;
        if (l == null) {
            if (this.o9 != null) {
                l = this.o9;
            }
            else {
                l = a.o5;
                k = true;
            }
        }
        var m = h;
        var n = h;
        var o = j;
        var 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);
        }
    };
    CrosshairLayer.prototype.uw = function (a, b) {
        var 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);
    };
    CrosshairLayer.prototype.uu = 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.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);
    };
    CrosshairLayer.prototype.r8 = function (a, b) {
        _super.prototype.r8.call(this, a, b);
        var c = this.td.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.v3 == 0;
        var l = this.v2 == 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.uu(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.uu(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.cw()) {
            this.uw(this.qr, true);
        }
        else {
            this.uw(this.qp, false);
        }
    };
    CrosshairLayer.prototype.ep = function () {
        return true;
    };
    CrosshairLayer.prototype.l9 = function (a, b, c, d) {
        _super.prototype.l9.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (d == null) {
                    if (this.tk != null && this.tk.count > 0) {
                        var e = void 0;
                        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;
}(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.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;
    };
    CrosshairLayerView.prototype.ce = 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.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.cb = function (a, b) {
        if (a == null) {
            return a;
        }
        return BrushUtil.l(a, b);
    };
    CrosshairLayerView.prototype.cd = function (a, b) {
        if (a == null) {
            return a;
        }
        return BrushUtil.n(a, b);
    };
    CrosshairLayerView.prototype.cc = function (a, b) {
        if (a == null) {
            return a;
        }
        var c = new Brush();
        c.color = Color.u(truncate((a.color.l * b)), a.color.o, a.color.n, a.color.m);
        return c;
    };
    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.a9.exportPathData(a, this.b6._inner[b], "crosshairLine", ["Main", "Crosshair"]);
        }
    };
    CrosshairLayerView.$t = markType(CrosshairLayerView, 'CrosshairLayerView', AnnotationLayerView.$);
    return CrosshairLayerView;
}(AnnotationLayerView));
export { CrosshairLayerView };
