/*
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, getEnumerator, Point_$type, fromEnum } from "igniteui-react-core";
import { CategoryFrame } from "./CategoryFrame";
import { Series } from "./Series";
import { SafeEnumerable } from "./SafeEnumerable";
import { TrendCalculators } from "igniteui-react-core";
import { AxisRange } from "./AxisRange";
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 { PropertyMetadata } from "igniteui-react-core";
import { isNaN_ } from "igniteui-react-core";
import { Flattener } from "igniteui-react-core";
/**
 * @hidden
 */
export let BollingerBandsOverlay = /*@__PURE__*/ (() => {
    class BollingerBandsOverlay extends FinancialOverlay {
        constructor() {
            super();
            this.p0 = 0;
            this.p1 = 0;
            this.py = new List$1(Number_$type, 0);
            this.pz = new List$1(Number_$type, 0);
            this.ab = BollingerBandsOverlay.$;
            this.ml = new CategoryFrame(4);
            this.mn = new CategoryFrame(4);
            this.mk = new CategoryFrame(4);
        }
        i7(a, b, c, d) {
            if (this.n1().contains(b)) {
                this.ps = false;
            }
            super.i7(a, b, c, d);
            switch (b) {
                case BollingerBandsOverlay.$$p[1]:
                    this.ps = false;
                    this.jl(false);
                    break;
                case BollingerBandsOverlay.$$p[0]:
                    this.jl(false);
                    break;
            }
        }
        pt() {
            this.py.clear();
            this.pz.clear();
            let a = getEnumerator(TrendCalculators.e(new SafeEnumerable(this.n0), this.p3));
            let b = getEnumerator(TrendCalculators.f(new SafeEnumerable(this.n0), this.p3));
            this.p1 = 1.7976931348623157E+308;
            this.p0 = -1.7976931348623157E+308;
            let c = true;
            let d = true;
            let e = this.p2;
            while (c || d) {
                if (a.moveNext()) {
                    this.py.add(a.current);
                }
                else {
                    c = false;
                }
                if (b.moveNext()) {
                    this.pz.add(b.current);
                }
                else {
                    d = false;
                }
                if (c && d) {
                    this.p1 = Math.min(this.p1, a.current - b.current * e);
                    this.p0 = Math.max(this.p0, a.current + b.current * e);
                }
            }
            return true;
        }
        an(a) {
            if (this.py == null || this.pz == null || a == null || this.bz == null || a != this.m3) {
                return null;
            }
            let b = new AxisRange(this.p1, this.p0);
            return b;
        }
        o9(a, b) {
            super.o9(a, b);
            let c = b.bs;
            let d = b.br;
            let e = this.getEffectiveViewport1(b);
            let f = this.mi;
            let g = this.m3;
            let h = new ScalerParams(0, c, d, f.ca, e);
            let i = new ScalerParams(0, c, d, g.ca, e);
            a.f.clear();
            a.m.clear();
            a.p.clear();
            let j = typeCast(ISortingAxis_$type, this.mi);
            if (j != null && j.i$b.count != this.bz.count) {
                return;
            }
            let k = 0;
            k = this.n9(c, d, e);
            if (!this.ps) {
                this.ps = this.pt();
                if (this.m3 != null) {
                    this.m3.co(true);
                }
            }
            i.b = this.eh();
            let l = this.mi.d1(2, h) - this.mi.d1(1, h);
            for (let m = b.bu.c; m <= b.bu.d; ++m) {
                let n;
                if (j == null) {
                    n = b.bu.getBucket(m);
                }
                else {
                    let o = j.i$b._inner[m];
                    let p = j.i$d(o);
                    let q = this.py._inner[m];
                    let r = this.pz._inner[m];
                    let s = q;
                    let t = r;
                    let u = p;
                    let v = 1;
                    while (m < b.bu.d) {
                        o = j.i$b._inner[m + 1];
                        u = j.i$d(o);
                        if (u - p > l) {
                            break;
                        }
                        m++;
                        s += this.py._inner[m];
                        t += this.pz._inner[m];
                        v++;
                    }
                    s /= v;
                    t /= v;
                    let w = s - t * this.p2;
                    let x = s;
                    let y = s + t * this.p2;
                    let z = NaN;
                    if (!isNaN_(p)) {
                        z = this.mi.dy(p, h);
                    }
                    n = [z, w, x, y];
                }
                let aa = Math.max(1, l);
                if (!isNaN_(n[0]) && m * aa >= this.pu) {
                    if (this.mi != null && typeCast(ISortingAxis_$type, this.mi) !== null) {
                        n[0] = n[0] + k;
                    }
                    else {
                        n[0] = f.dy(n[0], h) + k;
                    }
                    n[1] = g.dy(n[1], i);
                    n[2] = g.dy(n[2], i);
                    n[3] = g.dy(n[3], i);
                    a.f.add(n);
                }
            }
        }
        h3(a, b) {
            super.h3(a, b);
            let c = b;
            if (c != null) {
                c.b1();
            }
        }
        en(a, b, c) {
            if (this.py == null) {
                return super.en(a, b, c);
            }
            let d = this.getEffectiveViewport1(this.bi);
            let e = this.n9(this.bi.bs, this.bi.br, d);
            let f = new ScalerParams(0, this.bi.bs, this.bi.br, this.mi.ca, d);
            f.c = this.bs.oh;
            return this.ep(this.py, a, this.mi, f, e, runOn(this, this.n8), b, c);
        }
        fe(a, b) {
            if (this.py == null) {
                return super.fe(a, b);
            }
            return this.ff(a, b, this.mi, runOn(this, this.n8), this.py);
        }
        fc(a, b) {
            if (this.py == null) {
                return super.fc(a, b);
            }
            return this.fd(a, b, this.mi, runOn(this, this.n8), this.py);
        }
        dw(a, b, c) {
            let d = super.dw(a, b, c);
            if (!this.nr(this.n1())) {
                d = false;
            }
            return d;
        }
        pb(a, b) {
            super.pb(a, b);
            let c = typeCast(BollingerBandsOverlayView.$, b);
            let d = this.getEffectiveViewport1(b);
            if (b.bx(a)) {
                c.b1();
                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[j][2];
                let j = (k) => a.f._inner[e - 1 - k][3];
                c.b2(e, f, g, h, i, j);
                b.bz(a);
            }
            this.mq.x(this, this.nq(), this.mi, runOn(this, this.ma), this.of(b), this.oh(b));
            let k = false;
            let l = this.mq.c;
            let m = a.f;
            let n = this.bz.count;
            if (l != null) {
                k = true;
            }
            if (k) {
                let o = new ScalerParams(0, b.bs, b.br, this.mi.ca, d);
                this.o8(m, -1, n, this.mi, o, b.n);
            }
            let p = c.b9;
            let q = c.ca;
            let r = c.cb;
            let s = c.b4;
            this.mq.ae(q, true, false, true, true);
            this.mq.ao = null;
            this.mq.an = null;
            this.mq.ae(p, true, false, false, true);
            this.mq.ae(r, true, false, false, true);
            this.mq.ae(s, false, true, false, false);
            s._opacity = this.mq.i * this.d6;
        }
        bf() {
            return new BollingerBandsOverlayView(this);
        }
        i2(a) {
            super.i2(a);
            this.px = typeCast(BollingerBandsOverlayView.$, a);
        }
        oi() {
            return 3;
        }
        eh() {
            return Series.ei(this.py, null);
        }
    }
    BollingerBandsOverlay.$t = /*@__PURE__*/ markType(BollingerBandsOverlay, 'BollingerBandsOverlay', FinancialOverlay.$);
    BollingerBandsOverlay.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, BollingerBandsOverlay, 'raisePropertyChanged', ['Multiplier:p2:p6', [1, 2], 'Period:p3:p7', [1, 14]]);
    return BollingerBandsOverlay;
})();
/**
 * @hidden
 */
export let BollingerBandsBucketCalculator = /*@__PURE__*/ (() => {
    class BollingerBandsBucketCalculator 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.bw.bz.count - 1);
            if (b <= c) {
                let d = this.f.b0.p2;
                let e = 0;
                let f = 0;
                let g = 0;
                for (let h = b; h <= c; ++h) {
                    if (!isNaN_(this.f.b0.py._inner[h]) && !isNaN_(this.f.b0.pz._inner[h])) {
                        e += this.f.b0.py._inner[h];
                        f += this.f.b0.pz._inner[h];
                        ++g;
                    }
                }
                if (g > 0) {
                    e = e / g;
                    f = f / g;
                    return [0.5 * (b + c), e - f * d, e, e + f * d];
                }
            }
            return [NaN, NaN, NaN, NaN];
        }
    }
    BollingerBandsBucketCalculator.$t = /*@__PURE__*/ markType(BollingerBandsBucketCalculator, 'BollingerBandsBucketCalculator', FinancialBucketCalculator.$);
    return BollingerBandsBucketCalculator;
})();
/**
 * @hidden
 */
export let BollingerBandsOverlayView = /*@__PURE__*/ (() => {
    class BollingerBandsOverlayView extends FinancialSeriesView {
        constructor(a) {
            super(a);
            this.b0 = null;
            this.b5 = new Polygon();
            this.cc = new Polyline();
            this.cd = new Polyline();
            this.ce = new Polyline();
            this.b3 = new Polygon();
            this.b6 = new Polyline();
            this.b7 = new Polyline();
            this.b8 = new Polyline();
            this.b0 = a;
        }
        ap() {
            super.ap();
            if (!this.n) {
                this.e.bj = 1;
            }
        }
        bv() {
            return new BollingerBandsBucketCalculator(this);
        }
        b2(a, b, c, d, e, f) {
            for (let g of fromEnum(Flattener.d(a, b, d, this.e.eu))) {
                this.b5.ak.add({ $type: Point_$type, x: b(g), y: d(g) });
                this.cc.ak.add({ $type: Point_$type, x: b(g), y: d(g) });
            }
            for (let h of fromEnum(Flattener.d(a, b, e, this.e.eu))) {
                this.cd.ak.add({ $type: Point_$type, x: b(h), y: e(h) });
            }
            for (let i of fromEnum(Flattener.d(a, c, f, this.e.eu))) {
                this.b5.ak.add({ $type: Point_$type, x: c(i), y: f(i) });
                this.ce.ak.add({ $type: Point_$type, x: c(i), y: f(i) });
            }
            this.an();
        }
        b1() {
            this.b5.ak.clear();
            this.cc.ak.clear();
            this.cd.ak.clear();
            this.ce.ak.clear();
            this.an();
        }
        get b4() {
            return this.b5;
        }
        get b9() {
            return this.cc;
        }
        get ca() {
            return this.cd;
        }
        get cb() {
            return this.ce;
        }
        a9() {
            super.a9();
            this.b3.ak = this.b5.ak;
            this.b6.ak = this.cc.ak;
            this.b7.ak = this.cd.ak;
            this.b8.ak = this.ce.ak;
            let a = this.bl();
            this.b3._fill = a;
            this.b3._opacity = 1;
            this.b6._stroke = a;
            this.b6.ac = this.e.ey + 3;
            this.b7._stroke = a;
            this.b7.ac = this.e.ey + 3;
            this.b8._stroke = a;
            this.b8.ac = this.e.ey + 3;
        }
        a3(a, b) {
            super.a3(a, b);
            if (a.d) {
                if (b) {
                    a.t(this.b3);
                    a.u(this.b6);
                    a.u(this.b7);
                    a.u(this.b8);
                }
                else {
                    a.t(this.b5);
                    a.u(this.cc);
                    a.u(this.cd);
                    a.u(this.ce);
                }
            }
        }
        ai(a) {
            super.ai(a);
            this.e.a2.exportPolygonData(a, this.b5, "FillShape", ["Fill"]);
            this.e.a2.exportPolylineData(a, this.cc, "BottomLine", ["Lower", "Main"]);
            this.e.a2.exportPolylineData(a, this.cd, "CentralLine", ["Central"]);
            this.e.a2.exportPolylineData(a, this.ce, "TopLine", ["Upper"]);
        }
    }
    BollingerBandsOverlayView.$t = /*@__PURE__*/ markType(BollingerBandsOverlayView, 'BollingerBandsOverlayView', FinancialSeriesView.$);
    return BollingerBandsOverlayView;
})();
//# sourceMappingURL=BollingerBandsOverlay_combined.js.map
