/*
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 {
        get_d7() {
            return true;
        }
        constructor() {
            super();
            this.xAxisAnnotationFormatLabel = null;
            this.yAxisAnnotationFormatLabel = null;
            this.zz = null;
            this.xe = null;
            this.xd = null;
            let a = new ValueLayerFrame();
            let b = new ValueLayerFrame();
            let c = new ValueLayerFrame();
            let d = this.ji / 1000;
            this.uf = a;
            this.ue = b;
            this.ug = c;
            this.ab = ValueLayer.$;
        }
        cg() {
            return new ValueLayerView(this);
        }
        o0(a) {
            super.o0(a);
            this.w6 = a;
        }
        w7() {
            return this.xAxisAnnotationFormatLabel != null;
        }
        w8() {
            return this.yAxisAnnotationFormatLabel != null;
        }
        get z1() {
            return new Thickness(1, this.xh, this.xj, this.xi, this.xg);
        }
        get z2() {
            return new Thickness(1, this.xn, this.xp, this.xo, this.xm);
        }
        vs(a, b) {
            if (this.w3 == null || this.w3 == a) {
                if (!this.at.c) {
                    this.pp(b);
                }
            }
        }
        vu(a, b) {
            super.vu(a, b);
            let c = a;
            let d = this.xc;
            let e = this.xb;
            c.af.clear();
            c.ag.clear();
            c.ae.clear();
            c.ah.clear();
            AxisAnnotationFrameManager.b(c);
            if (this.ul(this.w3)) {
                this.ys(this.w3, c, d, e);
            }
            else {
                let f = this.w4();
                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.cy.series)) {
                        if (!this.ul(k)) {
                            continue;
                        }
                        let l = k.ag();
                        for (let n = 0; n < l.length; n++) {
                            let m = l[n];
                            if (!this.xa(m)) {
                                continue;
                            }
                            let o = m.cp ? 1 : 0;
                            let p = i[o];
                            let q = null;
                            if (f == 5) {
                                let r = k.ic(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.ic(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.ic(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.tl(i);
                        this.yt(g, { $type: Point_$type, x: u.x, y: NaN }, c, d, e);
                    }
                    if (h != null && !isNaN_(i[1])) {
                        let v = h.tl(i);
                        this.yt(h, { $type: Point_$type, x: NaN, y: v.y }, c, d, e);
                    }
                }
                else {
                    for (let w of fromEnum(this.cy.series)) {
                        if (this.ul(w)) {
                            this.ys(w, c, d, e);
                        }
                        if (w.isStacked) {
                            w.n5((x) => {
                                if (this.ul(x)) {
                                    this.ys(x, c, d, e);
                                }
                                if (x.dv) {
                                    x.n3((y) => {
                                        if (this.ul(y)) {
                                            this.ys(y, c, d, e);
                                        }
                                        return true;
                                    });
                                }
                                return true;
                            });
                        }
                        if (w.dv) {
                            w.n3((x) => {
                                if (this.ul(x)) {
                                    this.ys(x, c, d, e);
                                }
                                return true;
                            });
                        }
                    }
                }
            }
        }
        ul(a) {
            if (!super.ul(a)) {
                return false;
            }
            if (this.x0 != null) {
                if (a.ep) {
                    let b = a.lu();
                    if (!Base.equalsStatic(this.x0, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.x0, a.name)) {
                        return false;
                    }
                }
            }
            return true;
        }
        xa(a) {
            if (!a.cj) {
                return false;
            }
            if (this.w0 != null && this.w0 != a) {
                return false;
            }
            if (this.xx != null && !Base.equalsStatic(this.xx, a.name)) {
                return false;
            }
            return true;
        }
        oo() {
            super.oo();
            if (!this.at.c && !this.dj()) {
                return;
            }
            if (this.dj()) {
                this.yu(this.ug, false);
            }
            else {
                this.yu(this.ue, false);
            }
        }
        w4() {
            if (this.w5 == 0) {
                return 2;
            }
            return this.w5;
        }
        t5() {
            return 3;
        }
        us() {
            return 0.3;
        }
        uv() {
            return -0.4;
        }
        uu() {
            return 0.5;
        }
        wr() {
            return this.t2 == 3 ? this.z0() : null;
        }
        ws() {
            return this.t3 == 3 ? this.z0() : null;
        }
        z0() {
            if (this.zz == null) {
                this.zz = new DoubleCollection();
                this.zz.add(DeviceUtils.g(5));
                this.zz.add(DeviceUtils.g(5));
            }
            return this.zz;
        }
        yt(a, b, c, d, e) {
            let f = false;
            let g = this.ss;
            if (g == null) {
                g = this.sw;
            }
            if (g == null) {
                g = a.ss;
                f = true;
            }
            let h = false;
            let i = this.zt;
            if (i == null) {
                if (this.sw != null) {
                    i = this.sw;
                }
                else {
                    i = a.ss;
                    h = true;
                }
            }
            let j = false;
            let k = this.zw;
            if (k == null) {
                if (this.sw != null) {
                    k = this.sw;
                }
                else {
                    k = a.ss;
                    j = true;
                }
            }
            let l = g;
            let m = g;
            let n = i;
            let o = k;
            if (this.zr != null) {
                l = this.zr;
            }
            else if (f) {
                switch (this.t2) {
                    case 1:
                        l = this.w6.ce(l, this.up);
                        break;
                    case 2:
                        l = this.w6.cg(l, this.up);
                        break;
                    case 4:
                        l = this.w6.cf(l, this.up);
                        break;
                }
            }
            if (this.zs != null) {
                m = this.zs;
            }
            else if (f) {
                switch (this.t3) {
                    case 1:
                        m = this.w6.ce(m, this.ur);
                        break;
                    case 2:
                        m = this.w6.cg(m, this.ur);
                        break;
                    case 4:
                        m = this.w6.cf(m, this.ur);
                        break;
                }
            }
            if (h) {
                switch (this.t3) {
                    case 1:
                        n = this.w6.ce(n, this.ur);
                        break;
                    case 2:
                        n = this.w6.cg(n, this.ur);
                        break;
                }
            }
            if (j) {
                switch (this.t2) {
                    case 1:
                        o = this.w6.ce(o, this.up);
                        break;
                    case 2:
                        o = this.w6.cg(o, this.up);
                        break;
                }
            }
            c.ae.add(l);
            c.ah.add(m);
            c.af.add(b.y);
            c.ag.add(b.x);
            if (this.w9) {
                AxisAnnotationFrameManager.c(c, b, a, this.cy, this.getEffectiveViewport(), g, n, this.xf, this.zv, this.zu, this.z1, this.xk, o, this.xl, this.zy, this.zx, this.z2, this.xq, this.z4 == 0, this.z3 == 0);
            }
        }
        ys(a, b, c, d) {
            let e = { $type: Point_$type, x: NaN, y: NaN };
            let f = this.w4();
            switch (f) {
                case 5:
                    e = a.tk(2);
                    break;
                case 4:
                    e = a.tk(1);
                    break;
                case 6:
                    e = a.tk(3);
                    break;
                default:
                    e = a.tk(f);
                    break;
            }
            let i = a.ag();
            for (let h = 0; h < i.length; h++) {
                let g = i[h];
                if (!this.xa(g)) {
                    continue;
                }
                if (g.cp) {
                    this.yt(a, { $type: Point_$type, x: NaN, y: e.y }, b, c, d);
                }
                else {
                    this.yt(a, { $type: Point_$type, x: e.x, y: NaN }, b, c, d);
                }
            }
        }
        yu(a, b) {
            let c = false;
            if (this.xd == null) {
                c = true;
                this.xe = new List$1(Axis.$, 0);
                this.xd = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
            }
            AxisAnnotationFrameManager.d(this, a, c, this.xd, this.xe, b, this.xr, this.xs, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
        }
        yr(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.hk;
            f.ai = e ? this.wq : this.wp;
            f.am = this.ta;
            f.al = this.s9;
            f.ak = this.s9;
            f.aj = this.s8;
            f.ac = this.il;
            return new Tuple$2(Path.$, Number_$type, f, b);
        }
        vx(a, b) {
            super.vx(a, b);
            let c = this.w6.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.z4 == 0;
            let l = this.z3 == 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.yr(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.yr(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.dj()) {
                this.yu(this.ug, true);
            }
            else {
                this.yu(this.ue, false);
            }
        }
        fm() {
            return true;
        }
        o8(a, b, c, d) {
            super.o8(a, b, c, d);
            switch (b) {
                case "SeriesViewer":
                    if (d == null) {
                        if (this.xd != null && this.xd.count > 0) {
                            let e;
                            if (this.dj()) {
                                e = this.ug;
                            }
                            else {
                                e = this.ue;
                            }
                            AxisAnnotationFrameManager.b(e);
                            AxisAnnotationFrameManager.d(this, e, true, this.xd, this.xe, true, this.xr, this.xs, this.xAxisAnnotationFormatLabel, this.yAxisAnnotationFormatLabel);
                        }
                    }
                    break;
                case ValueLayer.$$p[1]:
                    this.pp(true);
                    break;
                case ValueLayer.$$p[11]:
                    this.pp(true);
                    break;
                case ValueLayer.$$p[6]:
                case ValueLayer.$$p[7]:
                    this.pp(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.pp(true);
                    break;
            }
        }
    }
    ValueLayer.$t = /*@__PURE__*/ markType(ValueLayer, 'ValueLayer', AnnotationLayer.$);
    ValueLayer.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, ValueLayer, 'raisePropertyChanged', ['HorizontalLineStroke:zr:yv', [Brush.$, null], 'HorizontalLineVisibility:z3:yw', [Visibility_$type, /*@__PURE__*/ enumGetBox(Visibility_$type, 0)], 'IsAxisAnnotationEnabled:w9:yx', [0, false], 'SkipUnknownValues:xb:yy', [0, true], 'TargetAxisName:xx:yz', [2, null], 'TargetAxis:w0:y0', [Axis.$, null], 'TargetSeriesName:x0:y1', [2, null], 'TargetSeries:w3:y2', [Series.$, null], 'UseInterpolation:xc:y3', [0, true], 'ValueMode:w5:y4', [ValueLayerValueMode_$type, /*@__PURE__*/ enumGetBox(ValueLayerValueMode_$type, 2)], 'VerticalLineStroke:zs:y5', [Brush.$, null], 'VerticalLineVisibility:z4:y6', [Visibility_$type, /*@__PURE__*/ enumGetBox(Visibility_$type, 0)], 'XAxisAnnotationBackgroundCornerRadius:xf:y7', [1, /*@__PURE__*/ DeviceUtils.g(3)], 'XAxisAnnotationBackground:zt:y8', [Brush.$, null], 'XAxisAnnotationInterpolatedValuePrecision:xr:y9', [1, -1], 'XAxisAnnotationOutline:zu:za', [Brush.$, null], 'XAxisAnnotationPaddingBottom:xg:zb', [1, NaN], 'XAxisAnnotationPaddingLeft:xh:zc', [1, NaN], 'XAxisAnnotationPaddingRight:xi:zd', [1, NaN], 'XAxisAnnotationPaddingTop:xj:ze', [1, NaN], 'XAxisAnnotationStrokeThickness:xk:zf', [1, NaN], 'XAxisAnnotationTextColor:zv:zg', [Brush.$, null], 'YAxisAnnotationBackgroundCornerRadius:xl:zh', [1, /*@__PURE__*/ DeviceUtils.g(3)], 'YAxisAnnotationBackground:zw:zi', [Brush.$, null], 'YAxisAnnotationInterpolatedValuePrecision:xs:zj', [1, -1], 'YAxisAnnotationOutline:zx:zk', [Brush.$, null], 'YAxisAnnotationPaddingBottom:xm:zl', [1, NaN], 'YAxisAnnotationPaddingLeft:xn:zm', [1, NaN], 'YAxisAnnotationPaddingRight:xo:zn', [1, NaN], 'YAxisAnnotationPaddingTop:xp:zo', [1, NaN], 'YAxisAnnotationStrokeThickness:xq:zp', [1, NaN], 'YAxisAnnotationTextColor:zy:zq', [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.iu = 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.a9.exportPathData(a, this.b9._inner[b], "crosshairLine", ["Main", "Crosshair"]);
            }
        }
    }
    ValueLayerView.$t = /*@__PURE__*/ markType(ValueLayerView, 'ValueLayerView', AnnotationLayerView.$);
    return ValueLayerView;
})();
