/*
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 { Base, enumGetBox, Delegate_$type, Number_$type, fromEnum, Point_$type, markType, markDep, runOn } from "igniteui-react-core";
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 { 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.acp = null;
        _this.z0 = null;
        _this.zz = null;
        var a = new ValueLayerFrame();
        var b = new ValueLayerFrame();
        var c = new ValueLayerFrame();
        var d = _this.kb / 1000;
        _this.w3 = a;
        _this.w2 = b;
        _this.w4 = c;
        _this.ab = ValueLayer.$;
        return _this;
    }
    ValueLayer.prototype.bi = function () {
        return new ValueLayer();
    };
    ValueLayer.prototype.get_er = function () {
        return true;
    };
    ValueLayer.prototype.cq = function () {
        return new ValueLayerView(this);
    };
    ValueLayer.prototype.qw = function (a) {
        _super.prototype.qw.call(this, a);
        this.zu = a;
    };
    ValueLayer.prototype.gs = function (a) {
        if (this.zr == null) {
            return true;
        }
        if (this.zr == a) {
            return true;
        }
        return false;
    };
    Object.defineProperty(ValueLayer.prototype, "acr", {
        get: function () {
            return new Thickness(1, this.z3, this.z5, this.z4, this.z2);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ValueLayer.prototype, "acs", {
        get: function () {
            return new Thickness(1, this.z9, this.aab, this.aaa, this.z8);
        },
        enumerable: false,
        configurable: true
    });
    ValueLayer.prototype.yg = function (a, b) {
        if (this.zr == null || this.zr == a) {
            if (!this.a0.c) {
                this.rm(b);
            }
        }
    };
    ValueLayer.prototype.yi = function (a, b) {
        var e_1, _a, e_2, _b;
        var _this = this;
        _super.prototype.yi.call(this, a, b);
        var c = a;
        var d = this.zy;
        var e = this.zx;
        c.af.clear();
        c.ag.clear();
        c.ae.clear();
        c.ah.clear();
        AxisAnnotationFrameManager.b(c);
        if (this.w9(this.zr)) {
            this.abg(this.zr, c, d, e);
        }
        else {
            var f = this.zs();
            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.c9.series)), _d = _c.next(); !_d.done; _d = _c.next()) {
                        var k = _d.value;
                        if (!this.w9(k)) {
                            continue;
                        }
                        var l = k.ai();
                        for (var n = 0; n < l.length; n++) {
                            var m = l[n];
                            if (!this.zw(m)) {
                                continue;
                            }
                            var o = m.cp ? 1 : 0;
                            var p = i[o];
                            var q = null;
                            if (f == 5) {
                                var r = k.i6(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.i6(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.i6(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.v9(i);
                    this.abh(g, { $type: Point_$type, x: u.x, y: NaN }, c, d, e);
                }
                if (h != null && !isNaN_(i[1])) {
                    var v = h.v9(i);
                    this.abh(h, { $type: Point_$type, x: NaN, y: v.y }, c, d, e);
                }
            }
            else {
                try {
                    for (var _e = __values(fromEnum(this.c9.series)), _f = _e.next(); !_f.done; _f = _e.next()) {
                        var w = _f.value;
                        if (this.w9(w)) {
                            this.abg(w, c, d, e);
                        }
                        if (w.isStacked) {
                            w.py(function (x) {
                                if (_this.w9(x)) {
                                    _this.abg(x, c, d, e);
                                }
                                if (x.ee) {
                                    x.pw(function (y) {
                                        if (_this.w9(y)) {
                                            _this.abg(y, c, d, e);
                                        }
                                        return true;
                                    });
                                }
                                return true;
                            });
                        }
                        if (w.ee) {
                            w.pw(function (x) {
                                if (_this.w9(x)) {
                                    _this.abg(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.w9 = function (a) {
        if (!_super.prototype.w9.call(this, a)) {
            return false;
        }
        if (this.aam != null) {
            if (a.e9) {
                var b = a.m9();
                if (!Base.equalsStatic(this.aam, b)) {
                    return false;
                }
            }
            else {
                if (!Base.equalsStatic(this.aam, a.name)) {
                    return false;
                }
            }
        }
        return true;
    };
    ValueLayer.prototype.zw = function (a) {
        if (!a.cj) {
            return false;
        }
        if (this.zo != null && this.zo != a) {
            return false;
        }
        if (this.aaj != null && !Base.equalsStatic(this.aaj, a.name)) {
            return false;
        }
        return true;
    };
    ValueLayer.prototype.qk = function () {
        _super.prototype.qk.call(this);
        if (!this.a0.c && !this.d1()) {
            return;
        }
        if (this.d1()) {
            this.abi(this.w4, false);
        }
        else {
            this.abi(this.w2, false);
        }
    };
    ValueLayer.prototype.zs = function () {
        if (this.zt == 0) {
            return 2;
        }
        return this.zt;
    };
    ValueLayer.prototype.wt = function () {
        return 3;
    };
    ValueLayer.prototype.xg = function () {
        return 0.3;
    };
    ValueLayer.prototype.xj = function () {
        return -0.4;
    };
    ValueLayer.prototype.xi = function () {
        return 0.5;
    };
    ValueLayer.prototype.zf = function () {
        return this.wq == 3 ? this.acq() : null;
    };
    ValueLayer.prototype.zg = function () {
        return this.wr == 3 ? this.acq() : null;
    };
    ValueLayer.prototype.acq = function () {
        if (this.acp == null) {
            this.acp = new DoubleCollection();
            this.acp.add(DeviceUtils.g(5));
            this.acp.add(DeviceUtils.g(5));
        }
        return this.acp;
    };
    ValueLayer.prototype.abh = function (a, b, c, d, e) {
        var f = false;
        var g = this.u2;
        if (g == null) {
            g = this.u8;
        }
        if (g == null) {
            g = a.u2;
            f = true;
        }
        var h = false;
        var i = this.acj;
        if (i == null) {
            if (this.u8 != null) {
                i = this.u8;
            }
            else {
                i = a.u2;
                h = true;
            }
        }
        var j = false;
        var k = this.acm;
        if (k == null) {
            if (this.u8 != null) {
                k = this.u8;
            }
            else {
                k = a.u2;
                j = true;
            }
        }
        var l = g;
        var m = g;
        var n = i;
        var o = k;
        if (this.ach != null) {
            l = this.ach;
        }
        else if (f) {
            switch (this.wq) {
                case 1:
                    l = this.zu.ce(l, this.xd);
                    break;
                case 2:
                    l = this.zu.cg(l, this.xd);
                    break;
                case 4:
                    l = this.zu.cf(l, this.xd);
                    break;
            }
        }
        if (this.aci != null) {
            m = this.aci;
        }
        else if (f) {
            switch (this.wr) {
                case 1:
                    m = this.zu.ce(m, this.xf);
                    break;
                case 2:
                    m = this.zu.cg(m, this.xf);
                    break;
                case 4:
                    m = this.zu.cf(m, this.xf);
                    break;
            }
        }
        if (h) {
            switch (this.wr) {
                case 1:
                    n = this.zu.ce(n, this.xf);
                    break;
                case 2:
                    n = this.zu.cg(n, this.xf);
                    break;
            }
        }
        if (j) {
            switch (this.wq) {
                case 1:
                    o = this.zu.ce(o, this.xd);
                    break;
                case 2:
                    o = this.zu.cg(o, this.xd);
                    break;
            }
        }
        c.ae.add(l);
        c.ah.add(m);
        c.af.add(b.y);
        c.ag.add(b.x);
        if (this.zv) {
            AxisAnnotationFrameManager.c(c, b, a, this.c9, this.getEffectiveViewport(), g, n, this.z1, this.acl, this.ack, this.acr, this.z6, o, this.z7, this.aco, this.acn, this.acs, this.aac, this.acu == 0, this.act == 0);
        }
    };
    ValueLayer.prototype.abg = function (a, b, c, d) {
        var e = { $type: Point_$type, x: NaN, y: NaN };
        var f = this.zs();
        switch (f) {
            case 5:
                e = a.v8(2);
                break;
            case 4:
                e = a.v8(1);
                break;
            case 6:
                e = a.v8(3);
                break;
            default:
                e = a.v8(f);
                break;
        }
        var i = a.ai();
        for (var h = 0; h < i.length; h++) {
            var g = i[h];
            if (!this.zw(g)) {
                continue;
            }
            if (g.cp) {
                this.abh(a, { $type: Point_$type, x: NaN, y: e.y }, b, c, d);
            }
            else {
                this.abh(a, { $type: Point_$type, x: e.x, y: NaN }, b, c, d);
            }
        }
    };
    ValueLayer.prototype.abi = function (a, b) {
        var c = false;
        if (this.zz == null) {
            c = true;
            this.z0 = new List$1(Axis.$, 0);
            this.zz = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
        }
        AxisAnnotationFrameManager.d(this, a, c, this.zz, this.z0, b, this.aad, this.aae, this.zp, this.zq);
    };
    ValueLayer.prototype.abf = 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);
    };
    ValueLayer.prototype.yl = function (a, b) {
        _super.prototype.yl.call(this, a, b);
        var c = this.zu.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.acu == 0;
        var l = this.act == 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.abf(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.abf(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.abi(this.w4, true);
        }
        else {
            this.abi(this.w2, false);
        }
    };
    ValueLayer.prototype.f8 = function () {
        return true;
    };
    ValueLayer.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.zz != null && this.zz.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.zz, this.z0, true, this.aad, this.aae, this.zp, this.zq);
                    }
                }
                break;
            case ValueLayer.$$p[1]:
                this.rm(true);
                break;
            case ValueLayer.$$p[11]:
                this.rm(true);
                break;
            case ValueLayer.$$p[6]:
            case ValueLayer.$$p[7]:
            case "Visibility":
                this.rm(true);
                break;
            case ValueLayer.$$p[2]:
            case ValueLayer.$$p[13]:
            case ValueLayer.$$p[12]:
            case ValueLayer.$$p[16]:
            case ValueLayer.$$p[18]:
            case ValueLayer.$$p[20]:
            case ValueLayer.$$p[19]:
            case ValueLayer.$$p[17]:
            case ValueLayer.$$p[21]:
            case ValueLayer.$$p[22]:
            case ValueLayer.$$p[24]:
            case ValueLayer.$$p[27]:
            case ValueLayer.$$p[29]:
            case ValueLayer.$$p[31]:
            case ValueLayer.$$p[30]:
            case ValueLayer.$$p[28]:
            case ValueLayer.$$p[32]:
            case ValueLayer.$$p[33]:
            case ValueLayer.$$p[0]:
            case ValueLayer.$$p[10]:
            case ValueLayer.$$p[8]:
                this.rm(true);
                break;
        }
    };
    ValueLayer.prototype.o2 = function (a, b) {
        _super.prototype.o2.call(this, a, b);
        if (a) {
            AxisAnnotationFrameManager.b(this.w2);
            this.abi(this.w2, false);
        }
    };
    ValueLayer.$t = markType(ValueLayer, 'ValueLayer', AnnotationLayer.$);
    ValueLayer.$$p = markDep(DependencyProperty, PropertyMetadata, ValueLayer, 'raisePropertyChanged', ['HorizontalLineStroke:ach:abj', [Brush.$, null], 'HorizontalLineVisibility:act:abk', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:zv:abl', [0, false], 'SkipUnknownValues:zx:abm', [0, true], 'TargetAxisName:aaj:abn', [2, null], 'TargetAxis:zo:abo', [Axis.$, null], 'TargetSeriesName:aam:abp', [2, null], 'TargetSeries:zr:abq', [Series.$, null], 'UseInterpolation:zy:abr', [0, true], 'ValueMode:zt:abs', [ValueLayerValueMode_$type, enumGetBox(ValueLayerValueMode_$type, 2)], 'VerticalLineStroke:aci:abt', [Brush.$, null], 'VerticalLineVisibility:acu:abu', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:z1:abv', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:acj:abw', [Brush.$, null], 'XAxisAnnotationFormatLabel:zp:abx', [Delegate_$type], 'XAxisAnnotationInterpolatedValuePrecision:aad:aby', [1, -1], 'XAxisAnnotationOutline:ack:abz', [Brush.$, null], 'XAxisAnnotationPaddingBottom:z2:ab0', [1, NaN], 'XAxisAnnotationPaddingLeft:z3:ab1', [1, NaN], 'XAxisAnnotationPaddingRight:z4:ab2', [1, NaN], 'XAxisAnnotationPaddingTop:z5:ab3', [1, NaN], 'XAxisAnnotationStrokeThickness:z6:ab4', [1, NaN], 'XAxisAnnotationTextColor:acl:ab5', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:z7:ab6', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:acm:ab7', [Brush.$, null], 'YAxisAnnotationFormatLabel:zq:ab8', [Delegate_$type], 'YAxisAnnotationInterpolatedValuePrecision:aae:ab9', [1, -1], 'YAxisAnnotationOutline:acn:aca', [Brush.$, null], 'YAxisAnnotationPaddingBottom:z8:acb', [1, NaN], 'YAxisAnnotationPaddingLeft:z9:acc', [1, NaN], 'YAxisAnnotationPaddingRight:aaa:acd', [1, NaN], 'YAxisAnnotationPaddingTop:aab:ace', [1, NaN], 'YAxisAnnotationStrokeThickness:aac:acf', [1, NaN], 'YAxisAnnotationTextColor:aco:acg', [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.jn = 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.bb.exportPathData(a, this.b9._inner[b], "crosshairLine", ["Main", "Crosshair"]);
        }
    };
    ValueLayerView.$t = markType(ValueLayerView, 'ValueLayerView', AnnotationLayerView.$);
    return ValueLayerView;
}(AnnotationLayerView));
export { ValueLayerView };
