/*
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 { ValueLayerValueMode_$type } from "./ValueLayerValueMode";
import { DependencyProperty } from "igniteui-react-core";
import { Brush } from "igniteui-react-core";
import { Series } from "./Series";
import { Axis } from "./Axis";
import { Thickness } from "igniteui-react-core";
import { Visibility_$type } from "igniteui-react-core";
import { ValueLayerFrame } from "./ValueLayerFrame";
import { List$1 } from "igniteui-react-core";
import { Dictionary$2 } from "igniteui-react-core";
import { Pool$1 } from "igniteui-react-core";
import { AxisAnnotation } from "./AxisAnnotation";
import { Base, enumGetBox, Number_$type, fromEnum, Point_$type, markType, markDep, runOn } from "igniteui-react-core";
import { AxisAnnotationFrameManager } from "./AxisAnnotationFrameManager";
import { DoubleCollection } from "igniteui-react-core";
import { DeviceUtils } from "igniteui-react-core";
import { Tuple$2 } 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 ValueLayer = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ValueLayer, _super);
    function ValueLayer() {
        var _this = _super.call(this) || this;
        _this.xAxisAnnotationFormatLabel = null;
        _this.yAxisAnnotationFormatLabel = null;
        _this.zz = null;
        _this.xe = null;
        _this.xd = null;
        var a = new ValueLayerFrame();
        var b = new ValueLayerFrame();
        var c = new ValueLayerFrame();
        var d = _this.ji / 1000;
        _this.uf = a;
        _this.ue = b;
        _this.ug = c;
        _this.ab = ValueLayer.$;
        return _this;
    }
    ValueLayer.prototype.get_d7 = function () {
        return true;
    };
    ValueLayer.prototype.cg = function () {
        return new ValueLayerView(this);
    };
    ValueLayer.prototype.o0 = function (a) {
        _super.prototype.o0.call(this, a);
        this.w6 = a;
    };
    ValueLayer.prototype.w7 = function () {
        return this.xAxisAnnotationFormatLabel != null;
    };
    ValueLayer.prototype.w8 = function () {
        return this.yAxisAnnotationFormatLabel != null;
    };
    Object.defineProperty(ValueLayer.prototype, "z1", {
        get: function () {
            return new Thickness(1, this.xh, this.xj, this.xi, this.xg);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ValueLayer.prototype, "z2", {
        get: function () {
            return new Thickness(1, this.xn, this.xp, this.xo, this.xm);
        },
        enumerable: false,
        configurable: true
    });
    ValueLayer.prototype.vs = function (a, b) {
        if (this.w3 == null || this.w3 == a) {
            if (!this.at.c) {
                this.pp(b);
            }
        }
    };
    ValueLayer.prototype.vu = function (a, b) {
        var e_1, _a, e_2, _b;
        var _this = this;
        _super.prototype.vu.call(this, a, b);
        var c = a;
        var d = this.xc;
        var e = this.xb;
        c.af.clear();
        c.ag.clear();
        c.ae.clear();
        c.ah.clear();
        AxisAnnotationFrameManager.b(c);
        if (this.ul(this.w3)) {
            this.ys(this.w3, c, d, e);
        }
        else {
            var f = this.w4();
            if (f == 5 || f == 4 || f == 6) {
                var g = null;
                var h = null;
                var i = [NaN, NaN];
                var j = 0;
                try {
                    for (var _c = __values(fromEnum(this.cy.series)), _d = _c.next(); !_d.done; _d = _c.next()) {
                        var k = _d.value;
                        if (!this.ul(k)) {
                            continue;
                        }
                        var l = k.ag();
                        for (var n = 0; n < l.length; n++) {
                            var m = l[n];
                            if (!this.xa(m)) {
                                continue;
                            }
                            var o = m.cp ? 1 : 0;
                            var p = i[o];
                            var q = null;
                            if (f == 5) {
                                var r = k.ic(2, m);
                                if (!isNaN_(r) && (r > p || isNaN_(p))) {
                                    q = k;
                                }
                                p = !isNaN_(p) ? Math.max(r, p) : r;
                            }
                            else if (f == 4) {
                                var s = k.ic(1, m);
                                if (!isNaN_(s) && (s < p || isNaN_(p))) {
                                    q = k;
                                }
                                p = !isNaN_(p) ? Math.min(s, p) : s;
                            }
                            else if (f == 6) {
                                var t = k.ic(3, m);
                                q = k;
                                p = !isNaN_(p) ? p + t : t;
                            }
                            if (m.cp) {
                                h = q != null ? q : h;
                            }
                            else {
                                g = q != null ? q : g;
                            }
                            i[o] = p;
                        }
                        j++;
                    }
                }
                catch (e_1_1) {
                    e_1 = { error: e_1_1 };
                }
                finally {
                    try {
                        if (_d && !_d.done && (_a = _c.return))
                            _a.call(_c);
                    }
                    finally {
                        if (e_1)
                            throw e_1.error;
                    }
                }
                if (f == 6) {
                    i[0] = !isNaN_(i[0]) ? i[0] / j : NaN;
                    i[1] = !isNaN_(i[1]) ? i[1] / j : NaN;
                }
                if (g != null && !isNaN_(i[0])) {
                    var u = g.tl(i);
                    this.yt(g, { $type: Point_$type, x: u.x, y: NaN }, c, d, e);
                }
                if (h != null && !isNaN_(i[1])) {
                    var v = h.tl(i);
                    this.yt(h, { $type: Point_$type, x: NaN, y: v.y }, c, d, e);
                }
            }
            else {
                try {
                    for (var _e = __values(fromEnum(this.cy.series)), _f = _e.next(); !_f.done; _f = _e.next()) {
                        var w = _f.value;
                        if (this.ul(w)) {
                            this.ys(w, c, d, e);
                        }
                        if (w.isStacked) {
                            w.n5(function (x) {
                                if (_this.ul(x)) {
                                    _this.ys(x, c, d, e);
                                }
                                if (x.dv) {
                                    x.n3(function (y) {
                                        if (_this.ul(y)) {
                                            _this.ys(y, c, d, e);
                                        }
                                        return true;
                                    });
                                }
                                return true;
                            });
                        }
                        if (w.dv) {
                            w.n3(function (x) {
                                if (_this.ul(x)) {
                                    _this.ys(x, c, d, e);
                                }
                                return true;
                            });
                        }
                    }
                }
                catch (e_2_1) {
                    e_2 = { error: e_2_1 };
                }
                finally {
                    try {
                        if (_f && !_f.done && (_b = _e.return))
                            _b.call(_e);
                    }
                    finally {
                        if (e_2)
                            throw e_2.error;
                    }
                }
            }
        }
    };
    ValueLayer.prototype.ul = function (a) {
        if (!_super.prototype.ul.call(this, a)) {
            return false;
        }
        if (this.x0 != null) {
            if (a.ep) {
                var b = a.lu();
                if (!Base.equalsStatic(this.x0, b)) {
                    return false;
                }
            }
            else {
                if (!Base.equalsStatic(this.x0, a.name)) {
                    return false;
                }
            }
        }
        return true;
    };
    ValueLayer.prototype.xa = function (a) {
        if (!a.cj) {
            return false;
        }
        if (this.w0 != null && this.w0 != a) {
            return false;
        }
        if (this.xx != null && !Base.equalsStatic(this.xx, a.name)) {
            return false;
        }
        return true;
    };
    ValueLayer.prototype.oo = function () {
        _super.prototype.oo.call(this);
        if (!this.at.c && !this.dj()) {
            return;
        }
        if (this.dj()) {
            this.yu(this.ug, false);
        }
        else {
            this.yu(this.ue, false);
        }
    };
    ValueLayer.prototype.w4 = function () {
        if (this.w5 == 0) {
            return 2;
        }
        return this.w5;
    };
    ValueLayer.prototype.t5 = function () {
        return 3;
    };
    ValueLayer.prototype.us = function () {
        return 0.3;
    };
    ValueLayer.prototype.uv = function () {
        return -0.4;
    };
    ValueLayer.prototype.uu = function () {
        return 0.5;
    };
    ValueLayer.prototype.wr = function () {
        return this.t2 == 3 ? this.z0() : null;
    };
    ValueLayer.prototype.ws = function () {
        return this.t3 == 3 ? this.z0() : null;
    };
    ValueLayer.prototype.z0 = function () {
        if (this.zz == null) {
            this.zz = new DoubleCollection();
            this.zz.add(DeviceUtils.g(5));
            this.zz.add(DeviceUtils.g(5));
        }
        return this.zz;
    };
    ValueLayer.prototype.yt = function (a, b, c, d, e) {
        var f = false;
        var g = this.ss;
        if (g == null) {
            g = this.sw;
        }
        if (g == null) {
            g = a.ss;
            f = true;
        }
        var h = false;
        var i = this.zt;
        if (i == null) {
            if (this.sw != null) {
                i = this.sw;
            }
            else {
                i = a.ss;
                h = true;
            }
        }
        var j = false;
        var k = this.zw;
        if (k == null) {
            if (this.sw != null) {
                k = this.sw;
            }
            else {
                k = a.ss;
                j = true;
            }
        }
        var l = g;
        var m = g;
        var n = i;
        var o = k;
        if (this.zr != null) {
            l = this.zr;
        }
        else if (f) {
            switch (this.t2) {
                case 1:
                    l = this.w6.ce(l, this.up);
                    break;
                case 2:
                    l = this.w6.cg(l, this.up);
                    break;
                case 4:
                    l = this.w6.cf(l, this.up);
                    break;
            }
        }
        if (this.zs != null) {
            m = this.zs;
        }
        else if (f) {
            switch (this.t3) {
                case 1:
                    m = this.w6.ce(m, this.ur);
                    break;
                case 2:
                    m = this.w6.cg(m, this.ur);
                    break;
                case 4:
                    m = this.w6.cf(m, this.ur);
                    break;
            }
        }
        if (h) {
            switch (this.t3) {
                case 1:
                    n = this.w6.ce(n, this.ur);
                    break;
                case 2:
                    n = this.w6.cg(n, this.ur);
                    break;
            }
        }
        if (j) {
            switch (this.t2) {
                case 1:
                    o = this.w6.ce(o, this.up);
                    break;
                case 2:
                    o = this.w6.cg(o, this.up);
                    break;
            }
        }
        c.ae.add(l);
        c.ah.add(m);
        c.af.add(b.y);
        c.ag.add(b.x);
        if (this.w9) {
            AxisAnnotationFrameManager.c(c, b, a, this.cy, this.getEffectiveViewport(), g, n, this.xf, this.zv, this.zu, this.z1, this.xk, o, this.xl, this.zy, this.zx, this.z2, this.xq, this.z4 == 0, this.z3 == 0);
        }
    };
    ValueLayer.prototype.ys = function (a, b, c, d) {
        var e = { $type: Point_$type, x: NaN, y: NaN };
        var f = this.w4();
        switch (f) {
            case 5:
                e = a.tk(2);
                break;
            case 4:
                e = a.tk(1);
                break;
            case 6:
                e = a.tk(3);
                break;
            default:
                e = a.tk(f);
                break;
        }
        var i = a.ag();
        for (var h = 0; h < i.length; h++) {
            var g = i[h];
            if (!this.xa(g)) {
                continue;
            }
            if (g.cp) {
                this.yt(a, { $type: Point_$type, x: NaN, y: e.y }, b, c, d);
            }
            else {
                this.yt(a, { $type: Point_$type, x: e.x, y: NaN }, b, c, d);
            }
        }
    };
    ValueLayer.prototype.yu = function (a, b) {
        var c = false;
        if (this.xd == null) {
            c = true;
            this.xe = new List$1(Axis.$, 0);
            this.xd = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
        }
        AxisAnnotationFrameManager.d(this, a, c, this.xd, this.xe, b, this.xr, this.xs, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
    };
    ValueLayer.prototype.yr = 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.hk;
        f.ai = e ? this.wq : this.wp;
        f.am = this.ta;
        f.al = this.s9;
        f.ak = this.s9;
        f.aj = this.s8;
        f.ac = this.il;
        return new Tuple$2(Path.$, Number_$type, f, b);
    };
    ValueLayer.prototype.vx = function (a, b) {
        _super.prototype.vx.call(this, a, b);
        var c = this.w6.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.z4 == 0;
        var l = this.z3 == 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_(o)) {
                    var q = this.yr(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)) {
                    var u = this.yr(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.dj()) {
            this.yu(this.ug, true);
        }
        else {
            this.yu(this.ue, false);
        }
    };
    ValueLayer.prototype.fm = function () {
        return true;
    };
    ValueLayer.prototype.o8 = function (a, b, c, d) {
        _super.prototype.o8.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (d == null) {
                    if (this.xd != null && this.xd.count > 0) {
                        var e = void 0;
                        if (this.dj()) {
                            e = this.ug;
                        }
                        else {
                            e = this.ue;
                        }
                        AxisAnnotationFrameManager.b(e);
                        AxisAnnotationFrameManager.d(this, e, true, this.xd, this.xe, true, this.xr, this.xs, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                    }
                }
                break;
            case ValueLayer.$$p[1]:
                this.pp(true);
                break;
            case ValueLayer.$$p[11]:
                this.pp(true);
                break;
            case ValueLayer.$$p[6]:
            case ValueLayer.$$p[7]:
                this.pp(true);
                break;
            case ValueLayer.$$p[2]:
            case ValueLayer.$$p[13]:
            case ValueLayer.$$p[12]:
            case ValueLayer.$$p[15]:
            case ValueLayer.$$p[17]:
            case ValueLayer.$$p[19]:
            case ValueLayer.$$p[18]:
            case ValueLayer.$$p[16]:
            case ValueLayer.$$p[20]:
            case ValueLayer.$$p[21]:
            case ValueLayer.$$p[23]:
            case ValueLayer.$$p[25]:
            case ValueLayer.$$p[27]:
            case ValueLayer.$$p[29]:
            case ValueLayer.$$p[28]:
            case ValueLayer.$$p[26]:
            case ValueLayer.$$p[30]:
            case ValueLayer.$$p[31]:
            case ValueLayer.$$p[0]:
            case ValueLayer.$$p[10]:
            case ValueLayer.$$p[8]:
                this.pp(true);
                break;
        }
    };
    ValueLayer.$t = markType(ValueLayer, 'ValueLayer', AnnotationLayer.$);
    ValueLayer.$$p = markDep(DependencyProperty, PropertyMetadata, ValueLayer, 'raisePropertyChanged', ['HorizontalLineStroke:zr:yv', [Brush.$, null], 'HorizontalLineVisibility:z3:yw', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:w9:yx', [0, false], 'SkipUnknownValues:xb:yy', [0, true], 'TargetAxisName:xx:yz', [2, null], 'TargetAxis:w0:y0', [Axis.$, null], 'TargetSeriesName:x0:y1', [2, null], 'TargetSeries:w3:y2', [Series.$, null], 'UseInterpolation:xc:y3', [0, true], 'ValueMode:w5:y4', [ValueLayerValueMode_$type, enumGetBox(ValueLayerValueMode_$type, 2)], 'VerticalLineStroke:zs:y5', [Brush.$, null], 'VerticalLineVisibility:z4:y6', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:xf:y7', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:zt:y8', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:xr:y9', [1, -1], 'XAxisAnnotationOutline:zu:za', [Brush.$, null], 'XAxisAnnotationPaddingBottom:xg:zb', [1, NaN], 'XAxisAnnotationPaddingLeft:xh:zc', [1, NaN], 'XAxisAnnotationPaddingRight:xi:zd', [1, NaN], 'XAxisAnnotationPaddingTop:xj:ze', [1, NaN], 'XAxisAnnotationStrokeThickness:xk:zf', [1, NaN], 'XAxisAnnotationTextColor:zv:zg', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:xl:zh', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:zw:zi', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:xs:zj', [1, -1], 'YAxisAnnotationOutline:zx:zk', [Brush.$, null], 'YAxisAnnotationPaddingBottom:xm:zl', [1, NaN], 'YAxisAnnotationPaddingLeft:xn:zm', [1, NaN], 'YAxisAnnotationPaddingRight:xo:zn', [1, NaN], 'YAxisAnnotationPaddingTop:xp:zo', [1, NaN], 'YAxisAnnotationStrokeThickness:xq:zp', [1, NaN], 'YAxisAnnotationTextColor:zy:zq', [Brush.$, null]]);
    return ValueLayer;
}(AnnotationLayer));
export { ValueLayer };
/**
 * @hidden
 */
var ValueLayerView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ValueLayerView, _super);
    function ValueLayerView(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;
    }
    ValueLayerView.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.iu = Defaults.j;
    };
    ValueLayerView.prototype.ch = function () {
        var a = new Path();
        a.j = new TranslateTransform();
        this.b9.add(a);
        return a;
    };
    ValueLayerView.prototype.ca = function (a) {
        a._visibility = 0;
    };
    ValueLayerView.prototype.cc = function (a) {
        a._visibility = 1;
    };
    ValueLayerView.prototype.cb = function (a) {
        this.b9.remove(a);
    };
    ValueLayerView.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;
        }
    };
    ValueLayerView.prototype.ce = function (a, b) {
        if (a == null) {
            return a;
        }
        return BrushUtil.m(a, b);
    };
    ValueLayerView.prototype.cg = function (a, b) {
        if (a == null) {
            return a;
        }
        return BrushUtil.o(a, b);
    };
    ValueLayerView.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;
    };
    ValueLayerView.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);
                }
            }
        }
    };
    ValueLayerView.prototype.an = function (a) {
        _super.prototype.an.call(this, a);
        for (var b = 0; b < this.b9.count; b++) {
            this.e.a9.exportPathData(a, this.b9._inner[b], "crosshairLine", ["Main", "Crosshair"]);
        }
    };
    ValueLayerView.$t = markType(ValueLayerView, 'ValueLayerView', AnnotationLayerView.$);
    return ValueLayerView;
}(AnnotationLayerView));
export { ValueLayerView };
