/*
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 { 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
 */
export let ValueLayer = /*@__PURE__*/ (() => {
    class ValueLayer extends AnnotationLayer {
        constructor() {
            super();
            this.xAxisAnnotationFormatLabel = null;
            this.yAxisAnnotationFormatLabel = null;
            this.wa = null;
            this.tp = null;
            this.to = null;
            let a = new ValueLayerFrame();
            let b = new ValueLayerFrame();
            let c = new ValueLayerFrame();
            let d = this.hr / 1000;
            this.qq = a;
            this.qp = b;
            this.qr = c;
            this.ab = ValueLayer.$;
        }
        get_de() {
            return true;
        }
        by() {
            return new ValueLayerView(this);
        }
        l4(a) {
            super.l4(a);
            this.th = a;
        }
        ti() {
            return this.xAxisAnnotationFormatLabel != null;
        }
        tj() {
            return this.yAxisAnnotationFormatLabel != null;
        }
        get wc() {
            return new Thickness(1, this.ts, this.tu, this.tt, this.tr);
        }
        get wd() {
            return new Thickness(1, this.ty, this.t0, this.tz, this.tx);
        }
        r3(a, b) {
            if (this.te == null || this.te == a) {
                if (!this.at.c) {
                    this.mn(b);
                }
            }
        }
        r5(a, b) {
            super.r5(a, b);
            let c = a;
            let d = this.tn;
            let 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 {
                let f = this.tf();
                if (f == 5 || f == 4 || f == 6) {
                    let g = null;
                    let h = null;
                    let i = [NaN, NaN];
                    let j = 0;
                    for (let k of fromEnum(this.ce.series)) {
                        if (!this.qw(k)) {
                            continue;
                        }
                        let l = k.ag();
                        for (let n = 0; n < l.length; n++) {
                            let m = l[n];
                            if (!this.tl(m)) {
                                continue;
                            }
                            let o = m.co ? 1 : 0;
                            let p = i[o];
                            let q = null;
                            if (f == 5) {
                                let 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) {
                                let 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) {
                                let 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++;
                    }
                    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])) {
                        let u = g.pw(i);
                        this.u4(g, { $type: Point_$type, x: u.x, y: NaN }, c, d, e);
                    }
                    if (h != null && !isNaN_(i[1])) {
                        let v = h.pw(i);
                        this.u4(h, { $type: Point_$type, x: NaN, y: v.y }, c, d, e);
                    }
                }
                else {
                    for (let w of fromEnum(this.ce.series)) {
                        if (this.qw(w)) {
                            this.u3(w, c, d, e);
                        }
                        if (w.isStacked) {
                            w.lf((x) => {
                                if (this.qw(x)) {
                                    this.u3(x, c, d, e);
                                }
                                return true;
                            });
                        }
                    }
                }
            }
        }
        qw(a) {
            if (!super.qw(a)) {
                return false;
            }
            if (this.ub != null) {
                if (a.dx) {
                    let b = a.ju();
                    if (!Base.equalsStatic(this.ub, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.ub, a.name)) {
                        return false;
                    }
                }
            }
            return true;
        }
        tl(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;
        }
        lx() {
            super.lx();
            if (!this.at.c && !this.cw()) {
                return;
            }
            if (this.cw()) {
                this.u5(this.qr, false);
            }
            else {
                this.u5(this.qp, false);
            }
        }
        tf() {
            if (this.tg == 0) {
                return 2;
            }
            return this.tg;
        }
        qg() {
            return 3;
        }
        q3() {
            return 0.3;
        }
        q6() {
            return -0.4;
        }
        q5() {
            return 0.5;
        }
        s2() {
            return this.qd == 3 ? this.wb() : null;
        }
        s3() {
            return this.qe == 3 ? this.wb() : null;
        }
        wb() {
            if (this.wa == null) {
                this.wa = new DoubleCollection();
                this.wa.add(DeviceUtils.g(5));
                this.wa.add(DeviceUtils.g(5));
            }
            return this.wa;
        }
        u4(a, b, c, d, e) {
            let f = false;
            let g = this.o5;
            if (g == null) {
                g = this.o9;
            }
            if (g == null) {
                g = a.o5;
                f = true;
            }
            let h = false;
            let i = this.v4;
            if (i == null) {
                if (this.o9 != null) {
                    i = this.o9;
                }
                else {
                    i = a.o5;
                    h = true;
                }
            }
            let j = false;
            let k = this.v7;
            if (k == null) {
                if (this.o9 != null) {
                    k = this.o9;
                }
                else {
                    k = a.o5;
                    j = true;
                }
            }
            let l = g;
            let m = g;
            let n = i;
            let 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);
            }
        }
        u3(a, b, c, d) {
            let e = { $type: Point_$type, x: NaN, y: NaN };
            let 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;
            }
            let i = a.ag();
            for (let h = 0; h < i.length; h++) {
                let 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);
                }
            }
        }
        u5(a, b) {
            let 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);
        }
        u2(a, b, c, d, e) {
            let 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);
        }
        r8(a, b) {
            super.r8(a, b);
            let c = this.th.b5;
            let d = a;
            let e = d.af.count;
            let f = 0;
            let g = b.bu.left;
            let h = b.bu.right;
            let i = b.bu.top;
            let j = b.bu.bottom;
            let k = this.wf == 0;
            let l = this.we == 0;
            for (let m = 0; m < e; m++) {
                let n = Math.floor(d.af._inner[m]);
                let o = Math.floor(d.ag._inner[m]);
                let p = null;
                if (k) {
                    if (!isNaN_(o)) {
                        let q = this.u2(c, f, m, d, true);
                        p = q.c;
                        f = q.d;
                        let r = new PathGeometry();
                        let s = new PathFigure();
                        s._startPoint = { $type: Point_$type, x: o, y: i };
                        let 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)) {
                        let u = this.u2(c, f, m, d, false);
                        p = u.c;
                        f = u.d;
                        let v = new PathGeometry();
                        let w = new PathFigure();
                        w._startPoint = { $type: Point_$type, x: g, y: n };
                        let 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);
            }
        }
        ep() {
            return true;
        }
        l9(a, b, c, d) {
            super.l9(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (d == null) {
                        if (this.to != null && this.to.count > 0) {
                            let e;
                            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;
})();
/**
 * @hidden
 */
export let ValueLayerView = /*@__PURE__*/ (() => {
    class ValueLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            this.b4 = null;
            this.b5 = null;
            this.b6 = null;
            this.b4 = a;
            this.b6 = new List$1(Path.$, 0);
        }
        as() {
            super.as();
            this.b5 = ((() => {
                let $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;
        }
        ce() {
            let a = new Path();
            a.j = new TranslateTransform();
            this.b6.add(a);
            return a;
        }
        b7(a) {
            a._visibility = 0;
        }
        b9(a) {
            a._visibility = 1;
        }
        b8(a) {
            this.b6.remove(a);
        }
        ca(a, b, c, d) {
            if (a.an == null || a.an.c.x != d || a.an.d.x != c) {
                let e = ((() => {
                    let $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;
            }
        }
        cb(a, b) {
            if (a == null) {
                return a;
            }
            return BrushUtil.l(a, b);
        }
        cd(a, b) {
            if (a == null) {
                return a;
            }
            return BrushUtil.n(a, b);
        }
        cc(a, b) {
            if (a == null) {
                return a;
            }
            let c = new Brush();
            c.color = Color.u(truncate((a.color.l * b)), a.color.o, a.color.n, a.color.m);
            return c;
        }
        a6(a, b) {
            super.a6(a, b);
            if (a.d && !b) {
                for (let c = 0; c < this.b6.count; c++) {
                    let d = this.b6._inner[c];
                    if (d._visibility == 0) {
                        a.t(d);
                    }
                }
            }
        }
        al(a) {
            super.al(a);
            for (let 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;
})();
