/*
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-react-core";
import { DependencyProperty } from "igniteui-react-core";
import { Series } from "./Series";
import { Thickness } from "igniteui-react-core";
import { Visibility_$type } from "igniteui-react-core";
import { CrosshairLayerFrame } from "./CrosshairLayerFrame";
import { List$1 } from "igniteui-react-core";
import { Axis } from "./Axis";
import { Dictionary$2 } from "igniteui-react-core";
import { Pool$1 } from "igniteui-react-core";
import { AxisAnnotation } from "./AxisAnnotation";
import { Base, Number_$type, enumGetBox, fromEnum, Point_$type, markType, markDep, runOn } from "igniteui-react-core";
import { AxisAnnotationFrameManager } from "./AxisAnnotationFrameManager";
import { Tuple$2 } from "igniteui-react-core";
import { DoubleCollection } from "igniteui-react-core";
import { DeviceUtils } from "igniteui-react-core";
import { Path } from "igniteui-react-core";
import { PathGeometry } from "igniteui-react-core";
import { PathFigure } from "igniteui-react-core";
import { LineSegment } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { isNaN_, truncate } from "igniteui-react-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { Defaults } from "./Defaults";
import { TranslateTransform } from "igniteui-react-core";
import { LineGeometry } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { Color } from "igniteui-react-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.acb = null;
        _this.zy = null;
        _this.zx = null;
        var a = new CrosshairLayerFrame();
        var b = new CrosshairLayerFrame();
        var c = new CrosshairLayerFrame();
        var d = _this.kb / 1000;
        _this.w3 = a;
        _this.w2 = b;
        _this.w4 = c;
        _this.ab = CrosshairLayer.$;
        return _this;
    }
    CrosshairLayer.prototype.bi = function () {
        return new CrosshairLayer();
    };
    CrosshairLayer.prototype.get_ep = function () {
        return true;
    };
    CrosshairLayer.prototype.get_en = function () {
        return true;
    };
    CrosshairLayer.prototype.cq = function () {
        return new CrosshairLayerView(this);
    };
    CrosshairLayer.prototype.qw = function (a) {
        _super.prototype.qw.call(this, a);
        this.zq = a;
    };
    CrosshairLayer.prototype.gs = function (a) {
        if (this.zr == null) {
            return true;
        }
        if (this.zr == a) {
            return true;
        }
        return false;
    };
    CrosshairLayer.prototype.zs = function () {
        return this.xAxisAnnotationFormatLabel != null;
    };
    CrosshairLayer.prototype.zt = function () {
        return this.yAxisAnnotationFormatLabel != null;
    };
    Object.defineProperty(CrosshairLayer.prototype, "acd", {
        get: function () {
            return new Thickness(1, this.z1, this.z3, this.z2, this.z0);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CrosshairLayer.prototype, "ace", {
        get: function () {
            return new Thickness(1, this.z7, this.z9, this.z8, this.z6);
        },
        enumerable: false,
        configurable: true
    });
    CrosshairLayer.prototype.yg = function (a, b) {
        if (this.zr == null || this.zr == a) {
            if (!this.a0.c) {
                this.rm(b);
            }
        }
    };
    CrosshairLayer.prototype.yi = function (a, b) {
        var e_1, _a;
        var _this = this;
        _super.prototype.yi.call(this, a, b);
        var c = a;
        var d = this.zw;
        var e = this.zv;
        c.af.clear();
        c.ag.clear();
        c.ae.clear();
        c.ah.clear();
        AxisAnnotationFrameManager.b(c);
        if (this.w9(this.zr)) {
            this.aa8(this.zr, c, d, e);
        }
        else {
            try {
                for (var _b = __values(fromEnum(this.c9.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var f = _c.value;
                    if (this.w9(f)) {
                        this.aa8(f, c, d, e);
                    }
                    if (f.isStacked) {
                        f.py(function (g) {
                            if (_this.w9(g)) {
                                _this.aa8(g, c, d, e);
                            }
                            if (g.ee) {
                                g.pw(function (h) {
                                    if (_this.w9(h)) {
                                        _this.aa8(h, c, d, e);
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    if (f.ee) {
                        f.pw(function (g) {
                            if (_this.w9(g)) {
                                _this.aa8(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.w9 = function (a) {
        if (!_super.prototype.w9.call(this, a)) {
            return false;
        }
        if (this.aah != null) {
            if (a.e9) {
                var b = a.m9();
                if (!Base.equalsStatic(this.aah, b)) {
                    return false;
                }
            }
            else {
                if (!Base.equalsStatic(this.aah, a.name)) {
                    return false;
                }
            }
        }
        var c = this.yb(a);
        if (!c.c) {
            return false;
        }
        return true;
    };
    CrosshairLayer.prototype.qk = function () {
        _super.prototype.qk.call(this);
        if (!this.a0.c && !this.d1()) {
            return;
        }
        if (this.d1()) {
            this.aa9(this.w4, false);
        }
        else {
            this.aa9(this.w2, false);
        }
    };
    CrosshairLayer.prototype.wt = function () {
        return 1;
    };
    CrosshairLayer.prototype.xg = function () {
        return 0.1;
    };
    CrosshairLayer.prototype.xj = function () {
        return -0.4;
    };
    CrosshairLayer.prototype.xi = function () {
        return 0.5;
    };
    CrosshairLayer.prototype.zf = function () {
        return this.wq == 3 ? this.acc() : null;
    };
    CrosshairLayer.prototype.zg = function () {
        return this.wr == 3 ? this.acc() : null;
    };
    CrosshairLayer.prototype.acc = function () {
        if (this.acb == null) {
            this.acb = new DoubleCollection();
            this.acb.add(DeviceUtils.g(5));
            this.acb.add(DeviceUtils.g(5));
        }
        return this.acb;
    };
    CrosshairLayer.prototype.aa8 = function (a, b, c, d) {
        var e = this.yb(a);
        if (!e.c) {
            return;
        }
        var f = e.d;
        f = a.v5(f, c, d);
        var g = false;
        var h = this.u2;
        if (h == null) {
            h = this.u8;
        }
        if (h == null) {
            h = a.u2;
            g = true;
        }
        var i = false;
        var j = this.ab5;
        if (j == null) {
            if (this.u8 != null) {
                j = this.u8;
            }
            else {
                j = a.u2;
                i = true;
            }
        }
        var k = false;
        var l = this.ab8;
        if (l == null) {
            if (this.u8 != null) {
                l = this.u8;
            }
            else {
                l = a.u2;
                k = true;
            }
        }
        var m = h;
        var n = h;
        var o = j;
        var p = l;
        if (this.ab3 != null) {
            m = this.ab3;
        }
        else if (g) {
            switch (this.wq) {
                case 0:
                case 1:
                    m = this.zq.ce(m, this.xd);
                    break;
                case 2:
                    m = this.zq.cg(m, this.xd);
                    break;
                case 4:
                    m = this.zq.cf(m, this.xd);
                    break;
            }
        }
        if (this.ab4 != null) {
            n = this.ab4;
        }
        else if (g) {
            switch (this.wr) {
                case 0:
                case 1:
                    n = this.zq.ce(n, this.xf);
                    break;
                case 2:
                    n = this.zq.cg(n, this.xf);
                    break;
                case 4:
                    n = this.zq.cf(n, this.xf);
                    break;
            }
        }
        if (i) {
            switch (this.wr) {
                case 1:
                    o = this.zq.ce(o, this.xf);
                    break;
                case 2:
                    o = this.zq.cg(o, this.xf);
                    break;
            }
        }
        if (k) {
            switch (this.wq) {
                case 1:
                    p = this.zq.ce(p, this.xd);
                    break;
                case 2:
                    p = this.zq.cg(p, this.xd);
                    break;
            }
        }
        b.ae.add(m);
        b.ah.add(n);
        b.af.add(f.y);
        b.ag.add(f.x);
        if (this.zu && !isNaN_(f.y)) {
            AxisAnnotationFrameManager.c(b, f, a, this.c9, this.getEffectiveViewport(), h, o, this.zz, this.ab7, this.ab6, this.acd, this.z4, p, this.z5, this.aca, this.ab9, this.ace, this.aaa, this.acg == 0, this.acf == 0);
        }
    };
    CrosshairLayer.prototype.aa9 = function (a, b) {
        var c = false;
        if (this.zx == null) {
            c = true;
            this.zy = new List$1(Axis.$, 0);
            this.zx = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
        }
        AxisAnnotationFrameManager.d(this, a, c, this.zx, this.zy, b, this.aab, this.aac, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
    };
    CrosshairLayer.prototype.aa7 = 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.ic;
        f.ai = e ? this.ze : this.zd;
        f.am = this.vy;
        f.al = this.vx;
        f.ak = this.vx;
        f.aj = this.vw;
        f.ac = this.jf;
        return new Tuple$2(Path.$, Number_$type, f, b);
    };
    CrosshairLayer.prototype.yl = function (a, b) {
        _super.prototype.yl.call(this, a, b);
        var c = this.zq.b8;
        var d = a;
        var e = d.af.count;
        var f = 0;
        var g = b.bx.left;
        var h = b.bx.right;
        var i = b.bx.top;
        var j = b.bx.bottom;
        var k = this.acg == 0;
        var l = this.acf == 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.aa7(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.aa7(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.d1()) {
            this.aa9(this.w4, true);
        }
        else {
            this.aa9(this.w2, false);
        }
    };
    CrosshairLayer.prototype.f8 = function () {
        return true;
    };
    CrosshairLayer.prototype.q4 = function (a, b, c, d) {
        _super.prototype.q4.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (d == null) {
                    if (this.zx != null && this.zx.count > 0) {
                        var e = void 0;
                        if (this.d1()) {
                            e = this.w4;
                        }
                        else {
                            e = this.w2;
                        }
                        AxisAnnotationFrameManager.b(e);
                        AxisAnnotationFrameManager.d(this, e, true, this.zx, this.zy, true, this.aab, this.aac, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                    }
                }
                break;
            case CrosshairLayer.$$p[1]:
                this.rm(true);
                break;
            case CrosshairLayer.$$p[8]:
                this.rm(true);
                break;
            case CrosshairLayer.$$p[4]:
            case CrosshairLayer.$$p[5]:
                this.rm(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.rm(true);
                break;
        }
    };
    CrosshairLayer.$t = markType(CrosshairLayer, 'CrosshairLayer', AnnotationLayer.$);
    CrosshairLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CrosshairLayer, 'raisePropertyChanged', ['HorizontalLineStroke:ab3:aba', [Brush.$, null], 'HorizontalLineVisibility:acf:abb', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:zu:abc', [0, false], 'SkipUnknownValues:zv:abd', [0, true], 'TargetSeriesName:aah:abe', [2, null], 'TargetSeries:zr:abf', [Series.$, null], 'UseInterpolation:zw:abg', [0, true], 'VerticalLineStroke:ab4:abh', [Brush.$, null], 'VerticalLineVisibility:acg:abi', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:zz:abj', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:ab5:abk', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:aab:abl', [1, -1], 'XAxisAnnotationOutline:ab6:abm', [Brush.$, null], 'XAxisAnnotationPaddingBottom:z0:abn', [1, NaN], 'XAxisAnnotationPaddingLeft:z1:abo', [1, NaN], 'XAxisAnnotationPaddingRight:z2:abp', [1, NaN], 'XAxisAnnotationPaddingTop:z3:abq', [1, NaN], 'XAxisAnnotationStrokeThickness:z4:abr', [1, NaN], 'XAxisAnnotationTextColor:ab7:abs', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:z5:abt', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:ab8:abu', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:aac:abv', [1, -1], 'YAxisAnnotationOutline:ab9:abw', [Brush.$, null], 'YAxisAnnotationPaddingBottom:z6:abx', [1, NaN], 'YAxisAnnotationPaddingLeft:z7:aby', [1, NaN], 'YAxisAnnotationPaddingRight:z8:abz', [1, NaN], 'YAxisAnnotationPaddingTop:z9:ab0', [1, NaN], 'YAxisAnnotationStrokeThickness:aaa:ab1', [1, NaN], 'YAxisAnnotationTextColor:aca:ab2', [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.b7 = null;
        _this.b8 = null;
        _this.b9 = null;
        _this.b7 = a;
        _this.b9 = new List$1(Path.$, 0);
        return _this;
    }
    CrosshairLayerView.prototype.au = function () {
        var _this = this;
        _super.prototype.au.call(this);
        this.b8 = ((function () {
            var $ret = new Pool$1(Path.$);
            $ret.create = runOn(_this, _this.ch);
            $ret.activate = runOn(_this, _this.ca);
            $ret.disactivate = runOn(_this, _this.cc);
            $ret.destroy = runOn(_this, _this.cb);
            return $ret;
        })());
        this.b7.jn = Defaults.j;
    };
    CrosshairLayerView.prototype.ch = function () {
        var a = new Path();
        a.j = new TranslateTransform();
        this.b9.add(a);
        return a;
    };
    CrosshairLayerView.prototype.ca = function (a) {
        a._visibility = 0;
    };
    CrosshairLayerView.prototype.cc = function (a) {
        a._visibility = 1;
    };
    CrosshairLayerView.prototype.cb = function (a) {
        this.b9.remove(a);
    };
    CrosshairLayerView.prototype.cd = 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.ce = function (a, b) {
        if (a == null) {
            return a;
        }
        return BrushUtil.m(a, b);
    };
    CrosshairLayerView.prototype.cg = function (a, b) {
        if (a == null) {
            return a;
        }
        return BrushUtil.o(a, b);
    };
    CrosshairLayerView.prototype.cf = 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.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        if (a.d && !b) {
            for (var c = 0; c < this.b9.count; c++) {
                var d = this.b9._inner[c];
                if (d._visibility == 0) {
                    a.t(d);
                }
            }
        }
    };
    CrosshairLayerView.prototype.an = function (a) {
        _super.prototype.an.call(this, a);
        for (var b = 0; b < this.b9.count; b++) {
            this.e.bb.exportPathData(a, this.b9._inner[b], "crosshairLine", ["Main", "Crosshair"]);
        }
    };
    CrosshairLayerView.$t = markType(CrosshairLayerView, 'CrosshairLayerView', AnnotationLayerView.$);
    return CrosshairLayerView;
}(AnnotationLayerView));
export { CrosshairLayerView };
