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