/*
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 { Base, enumGetBox, Delegate_$type, Number_$type, typeCast, fromEnum, Point_$type, markType, markDep, runOn } from "igniteui-angular-core";
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 { DataLegendSeriesContext } from "igniteui-angular-core";
import { DataLegendSeriesValueInfo } 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.zv = [NaN, NaN];
            this.zz = null;
            this.z0 = null;
            this.ac0 = null;
            this.aaa = null;
            this.z9 = null;
            let a = new ValueLayerFrame();
            let b = new ValueLayerFrame();
            let c = new ValueLayerFrame();
            let d = this.kd / 1000;
            this.xa = a;
            this.w9 = b;
            this.xb = c;
            this.ab = ValueLayer.$;
        }
        bj() {
            return new ValueLayer();
        }
        get_et() {
            return true;
        }
        cs() {
            return new ValueLayerView(this);
        }
        qz(a) {
            super.qz(a);
            this.z4 = a;
        }
        gu(a) {
            if (this.z1 == null) {
                return true;
            }
            if (this.z1 == a) {
                return true;
            }
            return false;
        }
        get ac2() {
            return new Thickness(1, this.aad, this.aaf, this.aae, this.aac);
        }
        get ac3() {
            return new Thickness(1, this.aaj, this.aal, this.aak, this.aai);
        }
        mc() {
            return "Value Layer";
        }
        get_isSummarizationSupported() {
            return false;
        }
        i5(a, b, c) {
            if (isNaN_(this.zv[0]) && isNaN_(this.zv[1])) {
                return super.i5(a, b, c);
            }
            if (!isNaN_(this.zv[0])) {
                return this.zv[0];
            }
            return this.zv[1];
        }
        getDataLegendSeriesContextAt(a, b) {
            if (isNaN_(this.zv[0]) || isNaN_(this.zv[1])) {
                return super.getDataLegendSeriesContextAt(a, b);
            }
            if (this.z1 == null) {
                let c = new DataLegendSeriesValueInfo();
                c.l = this.zv[0];
                c.a = 0;
                c.q = "Value";
                c.r = "Value";
                c.s = "";
                let d = new DataLegendSeriesValueInfo();
                d.l = this.zv[1];
                d.a = 0;
                d.q = "Value";
                d.r = "Value";
                d.s = "";
                let e = new DataLegendSeriesContext();
                e.e = ((() => {
                    let $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
                    $ret.add(c);
                    $ret.add(d);
                    return $ret;
                })());
                e.h = this.mc();
                return e;
            }
            let f = this.z1.getDataLegendSeriesContextAt(a, b);
            let g = typeCast(DataLegendSeriesContext.$, f);
            if (g == null || g.e == null) {
                return super.getDataLegendSeriesContextAt(a, b);
            }
            if (g.e.count == 0) {
                g.e._inner[0].l = isNaN_(this.zv[0]) ? this.zv[1] : this.zv[0];
            }
            else {
                g.e._inner[0].l = this.zv[0];
                g.e._inner[1].l = this.zv[1];
            }
            return g;
        }
        yn(a, b) {
            if (this.z1 == null || this.z1 == a) {
                if (!this.a1.c) {
                    this.rp(b);
                }
            }
        }
        yp(a, b) {
            super.yp(a, b);
            let c = a;
            let d = this.z8;
            let e = this.z7;
            c.af.clear();
            c.ag.clear();
            c.ae.clear();
            c.ah.clear();
            AxisAnnotationFrameManager.b(c);
            this.zv = [NaN, NaN];
            this.zz = null;
            this.z0 = null;
            let f = this.z2();
            if (this.xg(this.z1)) {
                let g = this.z1.aq(f);
                this.zv = g;
                this.abq(c, d, e, this.z1);
            }
            else {
                if (f == 5 || f == 4 || f == 6) {
                    let h = null;
                    let i = null;
                    let j = [NaN, NaN];
                    let k = 0;
                    for (let l of fromEnum(this.db.series)) {
                        if (!this.xg(l)) {
                            continue;
                        }
                        let m = l.ai();
                        for (let o = 0; o < m.length; o++) {
                            let n = m[o];
                            if (!this.z6(n)) {
                                continue;
                            }
                            let p = n.cp ? 1 : 0;
                            let q = j[p];
                            let r = null;
                            if (f == 5) {
                                let s = l.i8(2, n);
                                if (!isNaN_(s) && (s > q || isNaN_(q))) {
                                    r = l;
                                }
                                q = !isNaN_(q) ? Math.max(s, q) : s;
                            }
                            else if (f == 4) {
                                let t = l.i8(1, n);
                                if (!isNaN_(t) && (t < q || isNaN_(q))) {
                                    r = l;
                                }
                                q = !isNaN_(q) ? Math.min(t, q) : t;
                            }
                            else if (f == 6) {
                                let u = l.i8(3, n);
                                r = l;
                                q = !isNaN_(q) ? q + u : u;
                            }
                            if (n.cp) {
                                i = r != null ? r : i;
                            }
                            else {
                                h = r != null ? r : h;
                            }
                            j[p] = q;
                        }
                        k++;
                    }
                    if (f == 6) {
                        j[0] = !isNaN_(j[0]) ? j[0] / k : NaN;
                        j[1] = !isNaN_(j[1]) ? j[1] / k : NaN;
                    }
                    if (h != null && !isNaN_(j[0])) {
                        let v = h.we(j);
                        this.abs(h, { $type: Point_$type, x: v.x, y: NaN }, c, d, e);
                    }
                    if (i != null && !isNaN_(j[1])) {
                        let w = i.we(j);
                        this.abs(i, { $type: Point_$type, x: NaN, y: w.y }, c, d, e);
                    }
                    this.zv = j;
                    this.zz = h;
                    this.z0 = i;
                }
                else {
                    for (let x of fromEnum(this.db.series)) {
                        this.abq(c, d, e, x);
                    }
                }
            }
        }
        abq(a, b, c, d) {
            if (this.xg(d)) {
                this.abr(d, a, b, c);
            }
            if (d.isStacked) {
                d.p1((e) => {
                    if (this.xg(e)) {
                        this.abr(e, a, b, c);
                    }
                    if (e.eg) {
                        e.pz((f) => {
                            if (this.xg(f)) {
                                this.abr(f, a, b, c);
                            }
                            return true;
                        });
                    }
                    return true;
                });
            }
            if (d.eg) {
                d.pz((e) => {
                    if (this.xg(e)) {
                        this.abr(e, a, b, c);
                    }
                    return true;
                });
            }
        }
        xg(a) {
            if (!super.xg(a)) {
                return false;
            }
            if (this.aaw != null) {
                if (a.fb) {
                    let b = a.nc();
                    if (!Base.equalsStatic(this.aaw, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.aaw, a.name)) {
                        return false;
                    }
                }
            }
            return true;
        }
        z6(a) {
            if (!a.cj) {
                return false;
            }
            if (this.zw != null && this.zw != a) {
                return false;
            }
            if (this.aat != null && !Base.equalsStatic(this.aat, a.name)) {
                return false;
            }
            return true;
        }
        qn() {
            super.qn();
            if (!this.a1.c && !this.d3()) {
                return;
            }
            if (this.d3()) {
                this.abt(this.xb, false);
            }
            else {
                this.abt(this.w9, false);
            }
        }
        z2() {
            if (this.z3 == 0) {
                return 2;
            }
            return this.z3;
        }
        w0() {
            return 3;
        }
        xn() {
            return 0.3;
        }
        xq() {
            return -0.4;
        }
        xp() {
            return 0.5;
        }
        zm() {
            return this.wx == 3 ? this.ac1() : null;
        }
        zn() {
            return this.wy == 3 ? this.ac1() : null;
        }
        ac1() {
            if (this.ac0 == null) {
                this.ac0 = new DoubleCollection();
                this.ac0.add(DeviceUtils.g(5));
                this.ac0.add(DeviceUtils.g(5));
            }
            return this.ac0;
        }
        abs(a, b, c, d, e) {
            let f = false;
            let g = this.u7;
            if (g == null) {
                g = this.vd;
            }
            if (g == null) {
                g = a.u7;
                f = true;
            }
            let h = false;
            let i = this.acu;
            if (i == null) {
                if (this.vd != null) {
                    i = this.vd;
                }
                else {
                    i = a.u7;
                    h = true;
                }
            }
            let j = false;
            let k = this.acx;
            if (k == null) {
                if (this.vd != null) {
                    k = this.vd;
                }
                else {
                    k = a.u7;
                    j = true;
                }
            }
            let l = g;
            let m = g;
            let n = i;
            let o = k;
            if (this.acs != null) {
                l = this.acs;
            }
            else if (f) {
                switch (this.wx) {
                    case 1:
                        l = this.z4.ce(l, this.xk);
                        break;
                    case 2:
                        l = this.z4.cg(l, this.xk);
                        break;
                    case 4:
                        l = this.z4.cf(l, this.xk);
                        break;
                }
            }
            if (this.act != null) {
                m = this.act;
            }
            else if (f) {
                switch (this.wy) {
                    case 1:
                        m = this.z4.ce(m, this.xm);
                        break;
                    case 2:
                        m = this.z4.cg(m, this.xm);
                        break;
                    case 4:
                        m = this.z4.cf(m, this.xm);
                        break;
                }
            }
            if (h) {
                switch (this.wy) {
                    case 1:
                        n = this.z4.ce(n, this.xm);
                        break;
                    case 2:
                        n = this.z4.cg(n, this.xm);
                        break;
                }
            }
            if (j) {
                switch (this.wx) {
                    case 1:
                        o = this.z4.ce(o, this.xk);
                        break;
                    case 2:
                        o = this.z4.cg(o, this.xk);
                        break;
                }
            }
            c.ae.add(l);
            c.ah.add(m);
            c.af.add(b.y);
            c.ag.add(b.x);
            if (this.z5) {
                AxisAnnotationFrameManager.c(c, b, a, this.db, this.getEffectiveViewport(), g, n, this.aab, this.acw, this.acv, this.ac2, this.aag, o, this.aah, this.acz, this.acy, this.ac3, this.aam, this.ac5 == 0, this.ac4 == 0);
            }
        }
        abr(a, b, c, d) {
            let e = { $type: Point_$type, x: NaN, y: NaN };
            let f = this.z2();
            switch (f) {
                case 5:
                    e = a.wd(2);
                    break;
                case 4:
                    e = a.wd(1);
                    break;
                case 6:
                    e = a.wd(3);
                    break;
                default:
                    e = a.wd(f);
                    break;
            }
            let i = a.ai();
            for (let h = 0; h < i.length; h++) {
                let g = i[h];
                if (!this.z6(g)) {
                    continue;
                }
                if (g.cp) {
                    this.abs(a, { $type: Point_$type, x: NaN, y: e.y }, b, c, d);
                }
                else {
                    this.abs(a, { $type: Point_$type, x: e.x, y: NaN }, b, c, d);
                }
            }
        }
        abt(a, b) {
            let c = false;
            if (this.z9 == null) {
                c = true;
                this.aaa = new List$1(Axis.$, 0);
                this.z9 = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
            }
            AxisAnnotationFrameManager.d(this, a, c, this.z9, this.aaa, b, this.aan, this.aao, this.zx, this.zy);
        }
        abp(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.ie;
            f.ai = e ? this.zl : this.zk;
            f.am = this.v3;
            f.al = this.v2;
            f.ak = this.v2;
            f.aj = this.v1;
            f.ac = this.jh;
            return new Tuple$2(Path.$, Number_$type, f, b);
        }
        ys(a, b) {
            super.ys(a, b);
            let c = this.z4.b8;
            let d = a;
            let e = d.af.count;
            let f = 0;
            let g = b.bx.left;
            let h = b.bx.right;
            let i = b.bx.top;
            let j = b.bx.bottom;
            let k = this.ac5 == 0;
            let l = this.ac4 == 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.abp(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.abp(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.d3()) {
                this.abt(this.xb, true);
            }
            else {
                this.abt(this.w9, false);
            }
        }
        ga() {
            return true;
        }
        q7(a, b, c, d) {
            super.q7(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (d == null) {
                        if (this.z9 != null && this.z9.count > 0) {
                            let e;
                            if (this.d3()) {
                                e = this.xb;
                            }
                            else {
                                e = this.w9;
                            }
                            AxisAnnotationFrameManager.b(e);
                            AxisAnnotationFrameManager.d(this, e, true, this.z9, this.aaa, true, this.aan, this.aao, this.zx, this.zy);
                        }
                    }
                    break;
                case ValueLayer.$$p[1]:
                    this.rp(true);
                    break;
                case ValueLayer.$$p[11]:
                    this.rp(true);
                    break;
                case ValueLayer.$$p[6]:
                case ValueLayer.$$p[7]:
                case "Visibility":
                    this.rp(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.rp(true);
                    break;
            }
        }
        o5(a, b) {
            super.o5(a, b);
            if (a) {
                AxisAnnotationFrameManager.b(this.w9);
                this.abt(this.w9, false);
            }
        }
    }
    ValueLayer.$t = markType(ValueLayer, 'ValueLayer', AnnotationLayer.$);
    ValueLayer.$$p = markDep(DependencyProperty, PropertyMetadata, ValueLayer, 'raisePropertyChanged', ['HorizontalLineStroke:acs:abu', [Brush.$, null], 'HorizontalLineVisibility:ac4:abv', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:z5:abw', [0, false], 'SkipUnknownValues:z7:abx', [0, true], 'TargetAxisName:aat:aby', [2, null], 'TargetAxis:zw:abz', [Axis.$, null], 'TargetSeriesName:aaw:ab0', [2, null], 'TargetSeries:z1:ab1', [Series.$, null], 'UseInterpolation:z8:ab2', [0, true], 'ValueMode:z3:ab3', [ValueLayerValueMode_$type, enumGetBox(ValueLayerValueMode_$type, 2)], 'VerticalLineStroke:act:ab4', [Brush.$, null], 'VerticalLineVisibility:ac5:ab5', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:aab:ab6', [1, DeviceUtils.g(3)], 'XAxisAnnotationBackground:acu:ab7', [Brush.$, null], 'XAxisAnnotationFormatLabel:zx:ab8', [Delegate_$type], 'XAxisAnnotationInterpolatedValuePrecision:aan:ab9', [1, -1], 'XAxisAnnotationOutline:acv:aca', [Brush.$, null], 'XAxisAnnotationPaddingBottom:aac:acb', [1, NaN], 'XAxisAnnotationPaddingLeft:aad:acc', [1, NaN], 'XAxisAnnotationPaddingRight:aae:acd', [1, NaN], 'XAxisAnnotationPaddingTop:aaf:ace', [1, NaN], 'XAxisAnnotationStrokeThickness:aag:acf', [1, NaN], 'XAxisAnnotationTextColor:acw:acg', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:aah:ach', [1, DeviceUtils.g(3)], 'YAxisAnnotationBackground:acx:aci', [Brush.$, null], 'YAxisAnnotationFormatLabel:zy:acj', [Delegate_$type], 'YAxisAnnotationInterpolatedValuePrecision:aao:ack', [1, -1], 'YAxisAnnotationOutline:acy:acl', [Brush.$, null], 'YAxisAnnotationPaddingBottom:aai:acm', [1, NaN], 'YAxisAnnotationPaddingLeft:aaj:acn', [1, NaN], 'YAxisAnnotationPaddingRight:aak:aco', [1, NaN], 'YAxisAnnotationPaddingTop:aal:acp', [1, NaN], 'YAxisAnnotationStrokeThickness:aam:acq', [1, NaN], 'YAxisAnnotationTextColor:acz:acr', [Brush.$, null]]);
    return ValueLayer;
})();
/**
 * @hidden
 */
export let ValueLayerView = /*@__PURE__*/ (() => {
    class ValueLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            this.b7 = null;
            this.b8 = null;
            this.b9 = null;
            this.b7 = a;
            this.b9 = new List$1(Path.$, 0);
        }
        au() {
            super.au();
            this.b8 = ((() => {
                let $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.jp = Defaults.j;
        }
        ch() {
            let a = new Path();
            a.j = new TranslateTransform();
            this.b9.add(a);
            return a;
        }
        ca(a) {
            a._visibility = 0;
        }
        cc(a) {
            a._visibility = 1;
        }
        cb(a) {
            this.b9.remove(a);
        }
        cd(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;
            }
        }
        ce(a, b) {
            if (a == null) {
                return a;
            }
            return BrushUtil.m(a, b);
        }
        cg(a, b) {
            if (a == null) {
                return a;
            }
            return BrushUtil.o(a, b);
        }
        cf(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;
        }
        a8(a, b) {
            super.a8(a, b);
            if (a.d && !b) {
                for (let c = 0; c < this.b9.count; c++) {
                    let d = this.b9._inner[c];
                    if (d._visibility == 0) {
                        a.t(d);
                    }
                }
            }
        }
        an(a) {
            super.an(a);
            for (let b = 0; b < this.b9.count; b++) {
                this.e.bc.exportPathData(a, this.b9._inner[b], "crosshairLine", ["Main", "Crosshair"]);
            }
        }
    }
    ValueLayerView.$t = markType(ValueLayerView, 'ValueLayerView', AnnotationLayerView.$);
    return ValueLayerView;
})();
