/*
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 { FinancialOverlay } from "./FinancialOverlay";
import { DependencyProperty } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { Number_$type, typeCast, runOn, markType, markDep, Point_$type, fromEnum } from "igniteui-react-core";
import { CategoryFrame } from "./CategoryFrame";
import { Series } from "./Series";
import { MathUtil } from "igniteui-react-core";
import { FinancialSeriesView } from "./FinancialSeriesView";
import { ScalerParams } from "./ScalerParams";
import { ISortingAxis_$type } from "./ISortingAxis";
import { FinancialBucketCalculator } from "./FinancialBucketCalculator";
import { Polyline } from "igniteui-react-core";
import { Polygon } from "igniteui-react-core";
import { RangeValueList } from "./RangeValueList";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity } from "igniteui-react-core";
import { Flattener } from "igniteui-react-core";
/**
 * @hidden
 */
export let PriceChannelOverlay = /*@__PURE__*/ (() => {
    class PriceChannelOverlay extends FinancialOverlay {
        constructor() {
            super();
            this.rx = new List$1(Number_$type, 0);
            this.rw = new List$1(Number_$type, 0);
            this.ab = PriceChannelOverlay.$;
            this.ok = new CategoryFrame(3);
            this.om = new CategoryFrame(3);
            this.oj = new CategoryFrame(3);
        }
        kp(a, b, c, d) {
            switch (b) {
                case "HighColumn":
                case "LowColumn":
                    this.rq = false;
                    break;
            }
            super.kp(a, b, c, d);
            switch (b) {
                case PriceChannelOverlay.$$p[0]:
                    this.rq = false;
                    this.k3(false);
                    break;
            }
        }
        ec(a, b, c) {
            let d = super.ec(a, b, c);
            if (this.pa == null || this.pb == null) {
                d = false;
            }
            return d;
        }
        rr() {
            this.rx.clear();
            this.rw.clear();
            let a = truncate(MathUtil.b(this.ry, 0, this.cd.count));
            let b = Math.min(this.pa.count, this.pb.count);
            let c = this.p0(this.pa);
            let d = this.p0(this.pb);
            for (let e = 0; e < b; e++) {
                let f = Math.min(a, e);
                let g = -1.7976931348623157E+308;
                let h = 1.7976931348623157E+308;
                for (let i = 0; i < f; i++) {
                    if (!isNaN_(c.item(e - i))) {
                        g = Math.max(g, c.item(e - i));
                    }
                    if (!isNaN_(d.item(e - i))) {
                        h = Math.min(h, d.item(e - i));
                    }
                }
                if (e == 0) {
                    h = d.item(0);
                    g = c.item(0);
                }
                this.rx.add(g);
                this.rw.add(h);
            }
            return true;
        }
        q7(a, b) {
            super.q7(a, b);
            let c = b.bv;
            let d = b.bu;
            let e = this.getEffectiveViewport1(b);
            let f = new ScalerParams(0, c, d, this.oh.ca, e);
            let g = new ScalerParams(0, c, d, this.o2.ca, e);
            g.b = this.fa();
            let h = this.oh;
            let i = this.o2;
            a.f.clear();
            a.m.clear();
            a.p.clear();
            let j = 0;
            let k = typeCast(ISortingAxis_$type, this.oh);
            if (k != null && k.i$b.count != this.cd.count) {
                return;
            }
            j = this.p7(c, d, e);
            if (!this.rq) {
                this.rq = this.rr();
            }
            g.b = this.fa();
            let l = this.oh.d2(2, f) - this.oh.d2(1, f);
            for (let m = b.bx.c; m <= b.bx.d; ++m) {
                let n;
                if (k == null) {
                    n = b.bx.getBucket(m);
                }
                else {
                    let o = k.i$b._inner[m];
                    let p = k.i$d(o);
                    let q = this.rx._inner[m];
                    let r = this.rw._inner[m];
                    let s = q;
                    let t = r;
                    let u = p;
                    while (m < b.bx.d) {
                        o = k.i$b._inner[m + 1];
                        u = k.i$d(o);
                        if (u - p > l) {
                            break;
                        }
                        m++;
                        s = Math.max(q, this.rx._inner[m]);
                        t = Math.min(r, this.rw._inner[m]);
                    }
                    if (!isInfinity(t) && !isInfinity(s)) {
                        let v = NaN;
                        if (!isNaN_(p)) {
                            v = this.oh.dz(p, f);
                        }
                        n = [v, t, s];
                    }
                    else {
                        n = [NaN, NaN, NaN];
                    }
                }
                let w = Math.max(1, l);
                if (!isNaN_(n[0]) && m * w >= this.rs) {
                    if (this.oh != null && typeCast(ISortingAxis_$type, this.oh) !== null) {
                        n[0] = n[0] + j;
                    }
                    else {
                        n[0] = h.dz(n[0], f) + j;
                    }
                    n[1] = i.dz(n[1], g);
                    n[2] = i.dz(n[2], g);
                    a.f.add(n);
                }
            }
        }
        jl(a, b) {
            super.jl(a, b);
            let c = b;
            if (c != null) {
                c.b4();
            }
        }
        q9(a, b) {
            super.q9(a, b);
            let c = typeCast(PriceChannelOverlayView.$, b);
            if (c == null) {
                return;
            }
            let d = this.getEffectiveViewport1(b);
            if (b.b0(a)) {
                c.b4();
                let e = a.f.count;
                let f = (g) => a.f._inner[g][0];
                let g = (h) => a.f._inner[e - 1 - h][0];
                let h = (i) => a.f._inner[i][1];
                let i = (j) => a.f._inner[e - 1 - j][2];
                c.b5(e, f, g, h, i);
                b.b2(a);
            }
            this.op.a0(this, this.po(), runOn(this, this.n9), this.qd(b), this.qf(b));
            let j = false;
            let k = this.op.b;
            let l = a.f;
            let m = this.cd.count;
            if (k != null) {
                j = true;
            }
            if (j) {
                let n = new ScalerParams(0, b.bv, b.bu, this.oh.ca, d);
                this.q6(l, -1, m, this.oh, n, b.q);
            }
            let o = c.cb;
            let p = c.cc;
            let q = c.b7;
            this.op.ad(o, true, false, true, true);
            this.op.ad(p, true, false, true, true);
            this.op.ad(q, false, true, false, false);
            q._opacity = this.op.j * this.er;
        }
        bp() {
            return new PriceChannelOverlayView(this);
        }
        kk(a) {
            super.kk(a);
            this.rv = typeCast(PriceChannelOverlayView.$, a);
        }
        fh(a, b, c) {
            if (this.b6 == null) {
                return NaN;
            }
            let d = this.getEffectiveViewport1(this.bs);
            let e = new ScalerParams(0, this.b6.os, this.bs.bu, this.oh.ca, d);
            let f = this.p7(this.b6.os, this.bs.bu, d);
            return this.fj(new RangeValueList(this.rx, this.rw), a, this.oh, e, f, runOn(this, this.p6), b, c);
        }
        gd(a, b) {
            if (this.rx == null || this.rw == null) {
                return super.gd(a, b);
            }
            return this.ge(a, b, this.oh, runOn(this, this.p6), new RangeValueList(this.rx, this.rw));
        }
        gf(a, b) {
            if (this.rx == null || this.rw == null) {
                return super.gf(a, b);
            }
            return this.gg(a, b, this.oh, runOn(this, this.p6), new RangeValueList(this.rx, this.rw));
        }
        fa() {
            return Series.fb(this.rw, null);
        }
    }
    PriceChannelOverlay.$t = /*@__PURE__*/ markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:ry:r0', [1, 14]]);
    return PriceChannelOverlay;
})();
/**
 * @hidden
 */
export let PriceChannelBucketCalculator = /*@__PURE__*/ (() => {
    class PriceChannelBucketCalculator extends FinancialBucketCalculator {
        constructor(a) {
            super(a);
            this.f = null;
            this.f = a;
        }
        getBucket(a) {
            let b = a * this.b;
            let c = Math.min(b + this.b - 1, this.a.bz.cd.count - 1);
            if (b <= c) {
                let d = -1.7976931348623157E+308;
                let e = 1.7976931348623157E+308;
                let f = 0;
                for (let g = b; g <= c; ++g) {
                    if (!isNaN_(this.f.b3.rx._inner[g]) && !isNaN_(this.f.b3.rw._inner[g])) {
                        d = Math.max(d, this.f.b3.rx._inner[g]);
                        e = Math.min(e, this.f.b3.rw._inner[g]);
                        ++f;
                    }
                }
                if (f > 0 && e != 1.7976931348623157E+308 && d != -1.7976931348623157E+308) {
                    return [0.5 * (b + c), e, d];
                }
            }
            return [NaN, NaN, NaN];
        }
    }
    PriceChannelBucketCalculator.$t = /*@__PURE__*/ markType(PriceChannelBucketCalculator, 'PriceChannelBucketCalculator', FinancialBucketCalculator.$);
    return PriceChannelBucketCalculator;
})();
/**
 * @hidden
 */
export let PriceChannelOverlayView = /*@__PURE__*/ (() => {
    class PriceChannelOverlayView extends FinancialSeriesView {
        constructor(a) {
            super(a);
            this.b8 = new Polygon();
            this.cd = new Polyline();
            this.ce = new Polyline();
            this.b3 = null;
            this.b6 = new Polygon();
            this.b9 = new Polyline();
            this.ca = new Polyline();
            this.b3 = a;
        }
        get b7() {
            return this.b8;
        }
        get cb() {
            return this.cd;
        }
        get cc() {
            return this.ce;
        }
        as() {
            super.as();
            if (!this.q) {
                this.e.bx = 1;
            }
        }
        by() {
            return new PriceChannelBucketCalculator(this);
        }
        b4() {
            this.b8.ak.clear();
            this.cd.ak.clear();
            this.ce.ak.clear();
            this.aq();
        }
        b5(a, b, c, d, e) {
            for (let f of fromEnum(Flattener.d(a, b, d, this.e.fq))) {
                this.b8.ak.add({ $type: Point_$type, x: b(f), y: d(f) });
                this.cd.ak.add({ $type: Point_$type, x: b(f), y: d(f) });
            }
            for (let g of fromEnum(Flattener.d(a, c, e, this.e.fq))) {
                this.b8.ak.add({ $type: Point_$type, x: c(g), y: e(g) });
                this.ce.ak.add({ $type: Point_$type, x: c(g), y: e(g) });
            }
            this.aq();
        }
        bc() {
            super.bc();
            this.b6.ak = this.b8.ak;
            this.b9.ak = this.cd.ak;
            this.ca.ak = this.ce.ak;
            let a = this.bo();
            this.b6._fill = a;
            this.b6._opacity = 1;
            this.b9._stroke = a;
            this.b9.ac = this.e.eu + 3;
            this.ca._stroke = a;
            this.ca.ac = this.e.eu + 3;
        }
        a6(a, b) {
            super.a6(a, b);
            if (a.d) {
                if (b) {
                    a.t(this.b6);
                    a.u(this.b9);
                    a.u(this.ca);
                }
                else {
                    a.t(this.b8);
                    a.u(this.cd);
                    a.u(this.ce);
                }
            }
        }
        al(a) {
            super.al(a);
            this.e.a5.exportPolygonData(a, this.b8, "fill", ["Fill"]);
            this.e.a5.exportPolylineData(a, this.cd, "bottom", ["Lower", "Main"]);
            this.e.a5.exportPolylineData(a, this.ce, "top", ["Upper"]);
        }
    }
    PriceChannelOverlayView.$t = /*@__PURE__*/ markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
    return PriceChannelOverlayView;
})();
//# sourceMappingURL=PriceChannelOverlay_combined.js.map
