/*
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-angular-core";
import { Brush } from "igniteui-angular-core";
import { Series } from "./Series";
import { Axis } from "./Axis";
import { Thickness } from "igniteui-angular-core";
import { Visibility_$type } from "igniteui-angular-core";
import { ValueLayerFrame } from "./ValueLayerFrame";
import { List$1 } from "igniteui-angular-core";
import { Dictionary$2 } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { AxisAnnotation } from "./AxisAnnotation";
import { Base, enumGetBox, Number_$type, fromEnum, Point_$type, markType, markDep, runOn } from "igniteui-angular-core";
import { AxisAnnotationFrameManager } from "./AxisAnnotationFrameManager";
import { DoubleCollection } from "igniteui-angular-core";
import { DeviceUtils } from "igniteui-angular-core";
import { Tuple$2 } from "igniteui-angular-core";
import { Path } from "igniteui-angular-core";
import { PathGeometry } from "igniteui-angular-core";
import { PathFigure } from "igniteui-angular-core";
import { LineSegment } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_, truncate } from "igniteui-angular-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { Defaults } from "./Defaults";
import { TranslateTransform } from "igniteui-angular-core";
import { LineGeometry } from "igniteui-angular-core";
import { BrushUtil } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
/**
 * @hidden
 */
var ValueLayer = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ValueLayer, _super);
    function ValueLayer() {
        var _this = _super.call(this) || this;
        _this.xAxisAnnotationFormatLabel = null;
        _this.yAxisAnnotationFormatLabel = null;
        _this.wa = null;
        _this.tp = null;
        _this.to = null;
        var a = new ValueLayerFrame();
        var b = new ValueLayerFrame();
        var c = new ValueLayerFrame();
        var d = _this.hr / 1000;
        _this.qq = a;
        _this.qp = b;
        _this.qr = c;
        _this.ab = ValueLayer.$;
        return _this;
    }
    ValueLayer.prototype.get_de = function () {
        return true;
    };
    ValueLayer.prototype.by = function () {
        return new ValueLayerView(this);
    };
    ValueLayer.prototype.l4 = function (a) {
        _super.prototype.l4.call(this, a);
        this.th = a;
    };
    ValueLayer.prototype.ti = function () {
        return this.xAxisAnnotationFormatLabel != null;
    };
    ValueLayer.prototype.tj = function () {
        return this.yAxisAnnotationFormatLabel != null;
    };
    Object.defineProperty(ValueLayer.prototype, "wc", {
        get: function () {
            return new Thickness(1, this.ts, this.tu, this.tt, this.tr);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ValueLayer.prototype, "wd", {
        get: function () {
            return new Thickness(1, this.ty, this.t0, this.tz, this.tx);
        },
        enumerable: false,
        configurable: true
    });
    ValueLayer.prototype.r3 = function (a, b) {
        if (this.te == null || this.te == a) {
            if (!this.at.c) {
                this.mn(b);
            }
        }
    };
    ValueLayer.prototype.r5 = function (a, b) {
        var e_1, _a, e_2, _b;
        var _this = this;
        _super.prototype.r5.call(this, a, b);
        var c = a;
        var d = this.tn;
        var e = this.tm;
        c.af.clear();
        c.ag.clear();
        c.ae.clear();
        c.ah.clear();
        AxisAnnotationFrameManager.b(c);
        if (this.qw(this.te)) {
            this.u3(this.te, c, d, e);
        }
        else {
            var f = this.tf();
            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.ce.series)), _d = _c.next(); !_d.done; _d = _c.next()) {
                        var k = _d.value;
                        if (!this.qw(k)) {
                            continue;
                        }
                        var l = k.ag();
                        for (var n = 0; n < l.length; n++) {
                            var m = l[n];
                            if (!this.tl(m)) {
                                continue;
                            }
                            var o = m.co ? 1 : 0;
                            var p = i[o];
                            var q = null;
                            if (f == 5) {
                                var r = k.gq(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.gq(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.gq(3, m);
                                q = k;
                                p = !isNaN_(p) ? p + t : t;
                            }
                            if (m.co) {
                                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.pw(i);
                    this.u4(g, { $type: Point_$type, x: u.x, y: NaN }, c, d, e);
                }
                if (h != null && !isNaN_(i[1])) {
                    var v = h.pw(i);
                    this.u4(h, { $type: Point_$type, x: NaN, y: v.y }, c, d, e);
                }
            }
            else {
                try {
                    for (var _e = __values(fromEnum(this.ce.series)), _f = _e.next(); !_f.done; _f = _e.next()) {
                        var w = _f.value;
                        if (this.qw(w)) {
                            this.u3(w, c, d, e);
                        }
                        if (w.isStacked) {
                            w.lf(function (x) {
                                if (_this.qw(x)) {
                                    _this.u3(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.qw = function (a) {
        if (!_super.prototype.qw.call(this, a)) {
            return false;
        }
        if (this.ub != null) {
            if (a.dx) {
                var b = a.ju();
                if (!Base.equalsStatic(this.ub, b)) {
                    return false;
                }
            }
            else {
                if (!Base.equalsStatic(this.ub, a.name)) {
                    return false;
                }
            }
        }
        return true;
    };
    ValueLayer.prototype.tl = function (a) {
        if (!a.ci) {
            return false;
        }
        if (this.tb != null && this.tb != a) {
            return false;
        }
        if (this.t8 != null && !Base.equalsStatic(this.t8, a.name)) {
            return false;
        }
        return true;
    };
    ValueLayer.prototype.lx = function () {
        _super.prototype.lx.call(this);
        if (!this.at.c && !this.cw()) {
            return;
        }
        if (this.cw()) {
            this.u5(this.qr, false);
        }
        else {
            this.u5(this.qp, false);
        }
    };
    ValueLayer.prototype.tf = function () {
        if (this.tg == 0) {
            return 2;
        }
        return this.tg;
    };
    ValueLayer.prototype.qg = function () {
        return 3;
    };
    ValueLayer.prototype.q3 = function () {
        return 0.3;
    };
    ValueLayer.prototype.q6 = function () {
        return -0.4;
    };
    ValueLayer.prototype.q5 = function () {
        return 0.5;
    };
    ValueLayer.prototype.s2 = function () {
        return this.qd == 3 ? this.wb() : null;
    };
    ValueLayer.prototype.s3 = function () {
        return this.qe == 3 ? this.wb() : null;
    };
    ValueLayer.prototype.wb = function () {
        if (this.wa == null) {
            this.wa = new DoubleCollection();
            this.wa.add(DeviceUtils.g(5));
            this.wa.add(DeviceUtils.g(5));
        }
        return this.wa;
    };
    ValueLayer.prototype.u4 = function (a, b, c, d, e) {
        var f = false;
        var g = this.o5;
        if (g == null) {
            g = this.o9;
        }
        if (g == null) {
            g = a.o5;
            f = true;
        }
        var h = false;
        var i = this.v4;
        if (i == null) {
            if (this.o9 != null) {
                i = this.o9;
            }
            else {
                i = a.o5;
                h = true;
            }
        }
        var j = false;
        var k = this.v7;
        if (k == null) {
            if (this.o9 != null) {
                k = this.o9;
            }
            else {
                k = a.o5;
                j = true;
            }
        }
        var l = g;
        var m = g;
        var n = i;
        var o = k;
        if (this.v2 != null) {
            l = this.v2;
        }
        else if (f) {
            switch (this.qd) {
                case 1:
                    l = this.th.cb(l, this.q0);
                    break;
                case 2:
                    l = this.th.cd(l, this.q0);
                    break;
                case 4:
                    l = this.th.cc(l, this.q0);
                    break;
            }
        }
        if (this.v3 != null) {
            m = this.v3;
        }
        else if (f) {
            switch (this.qe) {
                case 1:
                    m = this.th.cb(m, this.q2);
                    break;
                case 2:
                    m = this.th.cd(m, this.q2);
                    break;
                case 4:
                    m = this.th.cc(m, this.q2);
                    break;
            }
        }
        if (h) {
            switch (this.qe) {
                case 1:
                    n = this.th.cb(n, this.q2);
                    break;
                case 2:
                    n = this.th.cd(n, this.q2);
                    break;
            }
        }
        if (j) {
            switch (this.qd) {
                case 1:
                    o = this.th.cb(o, this.q0);
                    break;
                case 2:
                    o = this.th.cd(o, this.q0);
                    break;
            }
        }
        c.ae.add(l);
        c.ah.add(m);
        c.af.add(b.y);
        c.ag.add(b.x);
        if (this.tk) {
            AxisAnnotationFrameManager.c(c, b, a, this.ce, this.getEffectiveViewport(), g, n, this.tq, this.v6, this.v5, this.wc, this.tv, o, this.tw, this.v9, this.v8, this.wd, this.t1, this.wf == 0, this.we == 0);
        }
    };
    ValueLayer.prototype.u3 = function (a, b, c, d) {
        var e = { $type: Point_$type, x: NaN, y: NaN };
        var f = this.tf();
        switch (f) {
            case 5:
                e = a.pv(2);
                break;
            case 4:
                e = a.pv(1);
                break;
            case 6:
                e = a.pv(3);
                break;
            default:
                e = a.pv(f);
                break;
        }
        var i = a.ag();
        for (var h = 0; h < i.length; h++) {
            var g = i[h];
            if (!this.tl(g)) {
                continue;
            }
            if (g.co) {
                this.u4(a, { $type: Point_$type, x: NaN, y: e.y }, b, c, d);
            }
            else {
                this.u4(a, { $type: Point_$type, x: e.x, y: NaN }, b, c, d);
            }
        }
    };
    ValueLayer.prototype.u5 = function (a, b) {
        var c = false;
        if (this.to == null) {
            c = true;
            this.tp = new List$1(Axis.$, 0);
            this.to = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
        }
        AxisAnnotationFrameManager.d(this, a, c, this.to, this.tp, b, this.t2, this.t3, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
    };
    ValueLayer.prototype.u2 = function (a, b, c, d, e) {
        var f = a.item(b);
        b++;
        if (e) {
            f._stroke = d.ah._inner[c];
            f._fill = d.ah._inner[c];
        }
        else {
            f._stroke = d.ae._inner[c];
            f._fill = d.ae._inner[c];
        }
        f.ad = this.fy;
        f.ai = e ? this.s1 : this.s0;
        f.am = this.pl;
        f.al = this.pk;
        f.ak = this.pk;
        f.aj = this.pj;
        f.ac = this.gw;
        return new Tuple$2(Path.$, Number_$type, f, b);
    };
    ValueLayer.prototype.r8 = function (a, b) {
        _super.prototype.r8.call(this, a, b);
        var c = this.th.b5;
        var d = a;
        var e = d.af.count;
        var f = 0;
        var g = b.bu.left;
        var h = b.bu.right;
        var i = b.bu.top;
        var j = b.bu.bottom;
        var k = this.wf == 0;
        var l = this.we == 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.u2(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.u2(c, f, m, d, false);
                    p = u.c;
                    f = u.d;
                    var v = new PathGeometry();
                    var w = new PathFigure();
                    w._startPoint = { $type: Point_$type, x: g, y: n };
                    var x = new LineSegment(1);
                    x.c = { $type: Point_$type, x: h, y: n };
                    w._segments.add(x);
                    v.c.add(w);
                    p.an = v;
                }
            }
        }
        c.count = f;
        if (this.cw()) {
            this.u5(this.qr, true);
        }
        else {
            this.u5(this.qp, false);
        }
    };
    ValueLayer.prototype.ep = function () {
        return true;
    };
    ValueLayer.prototype.l9 = function (a, b, c, d) {
        _super.prototype.l9.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                if (d == null) {
                    if (this.to != null && this.to.count > 0) {
                        var e = void 0;
                        if (this.cw()) {
                            e = this.qr;
                        }
                        else {
                            e = this.qp;
                        }
                        AxisAnnotationFrameManager.b(e);
                        AxisAnnotationFrameManager.d(this, e, true, this.to, this.tp, true, this.t2, this.t3, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                    }
                }
                break;
            case ValueLayer.$$p[1]:
                this.mn(true);
                break;
            case ValueLayer.$$p[11]:
                this.mn(true);
                break;
            case ValueLayer.$$p[6]:
            case ValueLayer.$$p[7]:
                this.mn(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.mn(true);
                break;
        }
    };
    ValueLayer.$t = markType(ValueLayer, 'ValueLayer', AnnotationLayer.$);
    ValueLayer.$$p = markDep(DependencyProperty, PropertyMetadata, ValueLayer, 'raisePropertyChanged', ['HorizontalLineStroke:v2:u6', [Brush.$, null], 'HorizontalLineVisibility:we:u7', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:tk:u8', [0, false], 'SkipUnknownValues:tm:u9', [0, true], 'TargetAxisName:t8:va', [2, null], 'TargetAxis:tb:vb', [Axis.$, null], 'TargetSeriesName:ub:vc', [2, null], 'TargetSeries:te:vd', [Series.$, null], 'UseInterpolation:tn:ve', [0, true], 'ValueMode:tg:vf', [ValueLayerValueMode_$type, enumGetBox(ValueLayerValueMode_$type, 2)], 'VerticalLineStroke:v3:vg', [Brush.$, null], 'VerticalLineVisibility:wf:vh', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:tq:vi', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:v4:vj', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:t2:vk', [1, -1], 'XAxisAnnotationOutline:v5:vl', [Brush.$, null], 'XAxisAnnotationPaddingBottom:tr:vm', [1, NaN], 'XAxisAnnotationPaddingLeft:ts:vn', [1, NaN], 'XAxisAnnotationPaddingRight:tt:vo', [1, NaN], 'XAxisAnnotationPaddingTop:tu:vp', [1, NaN], 'XAxisAnnotationStrokeThickness:tv:vq', [1, NaN], 'XAxisAnnotationTextColor:v6:vr', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:tw:vs', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:v7:vt', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:t3:vu', [1, -1], 'YAxisAnnotationOutline:v8:vv', [Brush.$, null], 'YAxisAnnotationPaddingBottom:tx:vw', [1, NaN], 'YAxisAnnotationPaddingLeft:ty:vx', [1, NaN], 'YAxisAnnotationPaddingRight:tz:vy', [1, NaN], 'YAxisAnnotationPaddingTop:t0:vz', [1, NaN], 'YAxisAnnotationStrokeThickness:t1:v0', [1, NaN], 'YAxisAnnotationTextColor:v9:v1', [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.b4 = null;
        _this.b5 = null;
        _this.b6 = null;
        _this.b4 = a;
        _this.b6 = new List$1(Path.$, 0);
        return _this;
    }
    ValueLayerView.prototype.as = function () {
        var _this = this;
        _super.prototype.as.call(this);
        this.b5 = ((function () {
            var $ret = new Pool$1(Path.$);
            $ret.create = runOn(_this, _this.ce);
            $ret.activate = runOn(_this, _this.b7);
            $ret.disactivate = runOn(_this, _this.b9);
            $ret.destroy = runOn(_this, _this.b8);
            return $ret;
        })());
        this.b4.g4 = Defaults.j;
    };
    ValueLayerView.prototype.ce = function () {
        var a = new Path();
        a.j = new TranslateTransform();
        this.b6.add(a);
        return a;
    };
    ValueLayerView.prototype.b7 = function (a) {
        a._visibility = 0;
    };
    ValueLayerView.prototype.b9 = function (a) {
        a._visibility = 1;
    };
    ValueLayerView.prototype.b8 = function (a) {
        this.b6.remove(a);
    };
    ValueLayerView.prototype.ca = function (a, b, c, d) {
        if (a.an == null || a.an.c.x != d || a.an.d.x != c) {
            var e = ((function () {
                var $ret = new LineGeometry();
                $ret.d = { $type: Point_$type, x: c, y: b };
                $ret.c = { $type: Point_$type, x: d, y: b };
                return $ret;
            })());
            a.an = e;
        }
    };
    ValueLayerView.prototype.cb = function (a, b) {
        if (a == null) {
            return a;
        }
        return BrushUtil.l(a, b);
    };
    ValueLayerView.prototype.cd = function (a, b) {
        if (a == null) {
            return a;
        }
        return BrushUtil.n(a, b);
    };
    ValueLayerView.prototype.cc = function (a, b) {
        if (a == null) {
            return a;
        }
        var c = new Brush();
        c.color = Color.u(truncate((a.color.l * b)), a.color.o, a.color.n, a.color.m);
        return c;
    };
    ValueLayerView.prototype.a6 = function (a, b) {
        _super.prototype.a6.call(this, a, b);
        if (a.d && !b) {
            for (var c = 0; c < this.b6.count; c++) {
                var d = this.b6._inner[c];
                if (d._visibility == 0) {
                    a.t(d);
                }
            }
        }
    };
    ValueLayerView.prototype.al = function (a) {
        _super.prototype.al.call(this, a);
        for (var b = 0; b < this.b6.count; b++) {
            this.e.a9.exportPathData(a, this.b6._inner[b], "crosshairLine", ["Main", "Crosshair"]);
        }
    };
    ValueLayerView.$t = markType(ValueLayerView, 'ValueLayerView', AnnotationLayerView.$);
    return ValueLayerView;
}(AnnotationLayerView));
export { ValueLayerView };
