/*
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.z1 = null;
        _this.xg = null;
        _this.xf = null;
        var a = new ValueLayerFrame();
        var b = new ValueLayerFrame();
        var c = new ValueLayerFrame();
        var d = _this.jj / 1000;
        _this.uh = a;
        _this.ug = b;
        _this.ui = c;
        _this.ab = ValueLayer.$;
        return _this;
    }
    ValueLayer.prototype.bc = function () {
        return new ValueLayer();
    };
    ValueLayer.prototype.get_d8 = function () {
        return true;
    };
    ValueLayer.prototype.cd = function () {
        return new ValueLayerView(this);
    };
    ValueLayer.prototype.o2 = function (a) {
        _super.prototype.o2.call(this, a);
        this.w8 = a;
    };
    ValueLayer.prototype.w9 = function () {
        return this.xAxisAnnotationFormatLabel != null;
    };
    ValueLayer.prototype.xa = function () {
        return this.yAxisAnnotationFormatLabel != null;
    };
    Object.defineProperty(ValueLayer.prototype, "z3", {
        get: function () {
            return new Thickness(1, this.xj, this.xl, this.xk, this.xi);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ValueLayer.prototype, "z4", {
        get: function () {
            return new Thickness(1, this.xp, this.xr, this.xq, this.xo);
        },
        enumerable: false,
        configurable: true
    });
    ValueLayer.prototype.vu = function (a, b) {
        if (this.w5 == null || this.w5 == a) {
            if (!this.at.c) {
                this.pr(b);
            }
        }
    };
    ValueLayer.prototype.vw = function (a, b) {
        var e_1, _a, e_2, _b;
        var _this = this;
        _super.prototype.vw.call(this, a, b);
        var c = a;
        var d = this.xe;
        var e = this.xd;
        c.af.clear();
        c.ag.clear();
        c.ae.clear();
        c.ah.clear();
        AxisAnnotationFrameManager.b(c);
        if (this.un(this.w5)) {
            this.yu(this.w5, c, d, e);
        }
        else {
            var f = this.w6();
            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.cv.series)), _d = _c.next(); !_d.done; _d = _c.next()) {
                        var k = _d.value;
                        if (!this.un(k)) {
                            continue;
                        }
                        var l = k.ag();
                        for (var n = 0; n < l.length; n++) {
                            var m = l[n];
                            if (!this.xc(m)) {
                                continue;
                            }
                            var o = m.cp ? 1 : 0;
                            var p = i[o];
                            var q = null;
                            if (f == 5) {
                                var r = k.id(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.id(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.id(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.tn(i);
                    this.yv(g, { $type: Point_$type, x: u.x, y: NaN }, c, d, e);
                }
                if (h != null && !isNaN_(i[1])) {
                    var v = h.tn(i);
                    this.yv(h, { $type: Point_$type, x: NaN, y: v.y }, c, d, e);
                }
            }
            else {
                try {
                    for (var _e = __values(fromEnum(this.cv.series)), _f = _e.next(); !_f.done; _f = _e.next()) {
                        var w = _f.value;
                        if (this.un(w)) {
                            this.yu(w, c, d, e);
                        }
                        if (w.isStacked) {
                            w.n6(function (x) {
                                if (_this.un(x)) {
                                    _this.yu(x, c, d, e);
                                }
                                if (x.dw) {
                                    x.n4(function (y) {
                                        if (_this.un(y)) {
                                            _this.yu(y, c, d, e);
                                        }
                                        return true;
                                    });
                                }
                                return true;
                            });
                        }
                        if (w.dw) {
                            w.n4(function (x) {
                                if (_this.un(x)) {
                                    _this.yu(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.un = function (a) {
        if (!_super.prototype.un.call(this, a)) {
            return false;
        }
        if (this.x2 != null) {
            if (a.eq) {
                var b = a.lv();
                if (!Base.equalsStatic(this.x2, b)) {
                    return false;
                }
            }
            else {
                if (!Base.equalsStatic(this.x2, a.name)) {
                    return false;
                }
            }
        }
        return true;
    };
    ValueLayer.prototype.xc = function (a) {
        if (!a.cj) {
            return false;
        }
        if (this.w2 != null && this.w2 != a) {
            return false;
        }
        if (this.xz != null && !Base.equalsStatic(this.xz, a.name)) {
            return false;
        }
        return true;
    };
    ValueLayer.prototype.oq = function () {
        _super.prototype.oq.call(this);
        if (!this.at.c && !this.dk()) {
            return;
        }
        if (this.dk()) {
            this.yw(this.ui, false);
        }
        else {
            this.yw(this.ug, false);
        }
    };
    ValueLayer.prototype.w6 = function () {
        if (this.w7 == 0) {
            return 2;
        }
        return this.w7;
    };
    ValueLayer.prototype.t7 = function () {
        return 3;
    };
    ValueLayer.prototype.uu = function () {
        return 0.3;
    };
    ValueLayer.prototype.ux = function () {
        return -0.4;
    };
    ValueLayer.prototype.uw = function () {
        return 0.5;
    };
    ValueLayer.prototype.wt = function () {
        return this.t4 == 3 ? this.z2() : null;
    };
    ValueLayer.prototype.wu = function () {
        return this.t5 == 3 ? this.z2() : null;
    };
    ValueLayer.prototype.z2 = function () {
        if (this.z1 == null) {
            this.z1 = new DoubleCollection();
            this.z1.add(DeviceUtils.g(5));
            this.z1.add(DeviceUtils.g(5));
        }
        return this.z1;
    };
    ValueLayer.prototype.yv = function (a, b, c, d, e) {
        var f = false;
        var g = this.su;
        if (g == null) {
            g = this.sy;
        }
        if (g == null) {
            g = a.su;
            f = true;
        }
        var h = false;
        var i = this.zv;
        if (i == null) {
            if (this.sy != null) {
                i = this.sy;
            }
            else {
                i = a.su;
                h = true;
            }
        }
        var j = false;
        var k = this.zy;
        if (k == null) {
            if (this.sy != null) {
                k = this.sy;
            }
            else {
                k = a.su;
                j = true;
            }
        }
        var l = g;
        var m = g;
        var n = i;
        var o = k;
        if (this.zt != null) {
            l = this.zt;
        }
        else if (f) {
            switch (this.t4) {
                case 1:
                    l = this.w8.ce(l, this.ur);
                    break;
                case 2:
                    l = this.w8.cg(l, this.ur);
                    break;
                case 4:
                    l = this.w8.cf(l, this.ur);
                    break;
            }
        }
        if (this.zu != null) {
            m = this.zu;
        }
        else if (f) {
            switch (this.t5) {
                case 1:
                    m = this.w8.ce(m, this.ut);
                    break;
                case 2:
                    m = this.w8.cg(m, this.ut);
                    break;
                case 4:
                    m = this.w8.cf(m, this.ut);
                    break;
            }
        }
        if (h) {
            switch (this.t5) {
                case 1:
                    n = this.w8.ce(n, this.ut);
                    break;
                case 2:
                    n = this.w8.cg(n, this.ut);
                    break;
            }
        }
        if (j) {
            switch (this.t4) {
                case 1:
                    o = this.w8.ce(o, this.ur);
                    break;
                case 2:
                    o = this.w8.cg(o, this.ur);
                    break;
            }
        }
        c.ae.add(l);
        c.ah.add(m);
        c.af.add(b.y);
        c.ag.add(b.x);
        if (this.xb) {
            AxisAnnotationFrameManager.c(c, b, a, this.cv, this.getEffectiveViewport(), g, n, this.xh, this.zx, this.zw, this.z3, this.xm, o, this.xn, this.z0, this.zz, this.z4, this.xs, this.z6 == 0, this.z5 == 0);
        }
    };
    ValueLayer.prototype.yu = function (a, b, c, d) {
        var e = { $type: Point_$type, x: NaN, y: NaN };
        var f = this.w6();
        switch (f) {
            case 5:
                e = a.tm(2);
                break;
            case 4:
                e = a.tm(1);
                break;
            case 6:
                e = a.tm(3);
                break;
            default:
                e = a.tm(f);
                break;
        }
        var i = a.ag();
        for (var h = 0; h < i.length; h++) {
            var g = i[h];
            if (!this.xc(g)) {
                continue;
            }
            if (g.cp) {
                this.yv(a, { $type: Point_$type, x: NaN, y: e.y }, b, c, d);
            }
            else {
                this.yv(a, { $type: Point_$type, x: e.x, y: NaN }, b, c, d);
            }
        }
    };
    ValueLayer.prototype.yw = function (a, b) {
        var c = false;
        if (this.xf == null) {
            c = true;
            this.xg = new List$1(Axis.$, 0);
            this.xf = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
        }
        AxisAnnotationFrameManager.d(this, a, c, this.xf, this.xg, b, this.xt, this.xu, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
    };
    ValueLayer.prototype.yt = 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.hl;
        f.ai = e ? this.ws : this.wr;
        f.am = this.tc;
        f.al = this.tb;
        f.ak = this.tb;
        f.aj = this.ta;
        f.ac = this.im;
        return new Tuple$2(Path.$, Number_$type, f, b);
    };
    ValueLayer.prototype.vz = function (a, b) {
        _super.prototype.vz.call(this, a, b);
        var c = this.w8.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.z6 == 0;
        var l = this.z5 == 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.yt(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.yt(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.dk()) {
            this.yw(this.ui, true);
        }
        else {
            this.yw(this.ug, false);
        }
    };
    ValueLayer.prototype.fn = function () {
        return true;
    };
    ValueLayer.prototype.pa = function (a, b, c, d) {
        _super.prototype.pa.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (d == null) {
                    if (this.xf != null && this.xf.count > 0) {
                        var e = void 0;
                        if (this.dk()) {
                            e = this.ui;
                        }
                        else {
                            e = this.ug;
                        }
                        AxisAnnotationFrameManager.b(e);
                        AxisAnnotationFrameManager.d(this, e, true, this.xf, this.xg, true, this.xt, this.xu, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                    }
                }
                break;
            case ValueLayer.$$p[1]:
                this.pr(true);
                break;
            case ValueLayer.$$p[11]:
                this.pr(true);
                break;
            case ValueLayer.$$p[6]:
            case ValueLayer.$$p[7]:
                this.pr(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.pr(true);
                break;
        }
    };
    ValueLayer.$t = markType(ValueLayer, 'ValueLayer', AnnotationLayer.$);
    ValueLayer.$$p = markDep(DependencyProperty, PropertyMetadata, ValueLayer, 'raisePropertyChanged', ['HorizontalLineStroke:zt:yx', [Brush.$, null], 'HorizontalLineVisibility:z5:yy', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:xb:yz', [0, false], 'SkipUnknownValues:xd:y0', [0, true], 'TargetAxisName:xz:y1', [2, null], 'TargetAxis:w2:y2', [Axis.$, null], 'TargetSeriesName:x2:y3', [2, null], 'TargetSeries:w5:y4', [Series.$, null], 'UseInterpolation:xe:y5', [0, true], 'ValueMode:w7:y6', [ValueLayerValueMode_$type, enumGetBox(ValueLayerValueMode_$type, 2)], 'VerticalLineStroke:zu:y7', [Brush.$, null], 'VerticalLineVisibility:z6:y8', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:xh:y9', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:zv:za', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:xt:zb', [1, -1], 'XAxisAnnotationOutline:zw:zc', [Brush.$, null], 'XAxisAnnotationPaddingBottom:xi:zd', [1, NaN], 'XAxisAnnotationPaddingLeft:xj:ze', [1, NaN], 'XAxisAnnotationPaddingRight:xk:zf', [1, NaN], 'XAxisAnnotationPaddingTop:xl:zg', [1, NaN], 'XAxisAnnotationStrokeThickness:xm:zh', [1, NaN], 'XAxisAnnotationTextColor:zx:zi', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:xn:zj', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:zy:zk', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:xu:zl', [1, -1], 'YAxisAnnotationOutline:zz:zm', [Brush.$, null], 'YAxisAnnotationPaddingBottom:xo:zn', [1, NaN], 'YAxisAnnotationPaddingLeft:xp:zo', [1, NaN], 'YAxisAnnotationPaddingRight:xq:zp', [1, NaN], 'YAxisAnnotationPaddingTop:xr:zq', [1, NaN], 'YAxisAnnotationStrokeThickness:xs:zr', [1, NaN], 'YAxisAnnotationTextColor:z0:zs', [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.iv = 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.a5.exportPathData(a, this.b9._inner[b], "crosshairLine", ["Main", "Crosshair"]);
        }
    };
    ValueLayerView.$t = markType(ValueLayerView, 'ValueLayerView', AnnotationLayerView.$);
    return ValueLayerView;
}(AnnotationLayerView));
export { ValueLayerView };
