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