/*
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 * as tslib_1 from "tslib";
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
 */
var BollingerBandsOverlay = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(BollingerBandsOverlay, _super);
    function BollingerBandsOverlay() {
        var _this = _super.call(this) || this;
        _this.ry = 0;
        _this.rz = 0;
        _this.rw = new List$1(Number_$type, 0);
        _this.rx = new List$1(Number_$type, 0);
        _this.ab = BollingerBandsOverlay.$;
        _this.ok = new CategoryFrame(4);
        _this.om = new CategoryFrame(4);
        _this.oj = new CategoryFrame(4);
        return _this;
    }
    BollingerBandsOverlay.prototype.kp = function (a, b, c, d) {
        if (this.pz().contains(b)) {
            this.rq = false;
        }
        _super.prototype.kp.call(this, a, b, c, d);
        switch (b) {
            case BollingerBandsOverlay.$$p[1]:
                this.rq = false;
                this.k3(false);
                break;
            case BollingerBandsOverlay.$$p[0]:
                this.k3(false);
                break;
        }
    };
    BollingerBandsOverlay.prototype.rr = function () {
        this.rw.clear();
        this.rx.clear();
        var a = getEnumerator(TrendCalculators.e(new SafeEnumerable(this.py), this.r1));
        var b = getEnumerator(TrendCalculators.f(new SafeEnumerable(this.py), this.r1));
        this.rz = 1.7976931348623157E+308;
        this.ry = -1.7976931348623157E+308;
        var c = true;
        var d = true;
        var e = this.r0;
        while (c || d) {
            if (a.moveNext()) {
                this.rw.add(a.current);
            }
            else {
                c = false;
            }
            if (b.moveNext()) {
                this.rx.add(b.current);
            }
            else {
                d = false;
            }
            if (c && d) {
                this.rz = Math.min(this.rz, a.current - b.current * e);
                this.ry = Math.max(this.ry, a.current + b.current * e);
            }
        }
        return true;
    };
    BollingerBandsOverlay.prototype.ao = function (a) {
        if (this.rw == null || this.rx == null || a == null || this.cd == null || a != this.o2) {
            return null;
        }
        var b = new AxisRange(this.rz, this.ry);
        return b;
    };
    BollingerBandsOverlay.prototype.q7 = function (a, b) {
        _super.prototype.q7.call(this, a, b);
        var c = b.bv;
        var d = b.bu;
        var e = this.getEffectiveViewport1(b);
        var f = this.oh;
        var g = this.o2;
        var h = new ScalerParams(0, c, d, f.ca, e);
        var i = new ScalerParams(0, c, d, g.ca, e);
        a.f.clear();
        a.m.clear();
        a.p.clear();
        var j = typeCast(ISortingAxis_$type, this.oh);
        if (j != null && j.i$b.count != this.cd.count) {
            return;
        }
        var k = 0;
        k = this.p7(c, d, e);
        if (!this.rq) {
            this.rq = this.rr();
            if (this.o2 != null) {
                this.o2.co(true);
            }
        }
        i.b = this.fa();
        var l = this.oh.d2(2, h) - this.oh.d2(1, h);
        for (var m = b.bx.c; m <= b.bx.d; ++m) {
            var n = void 0;
            if (j == null) {
                n = b.bx.getBucket(m);
            }
            else {
                var o = j.i$b._inner[m];
                var p = j.i$d(o);
                var q = this.rw._inner[m];
                var r = this.rx._inner[m];
                var s = q;
                var t = r;
                var u = p;
                var v = 1;
                while (m < b.bx.d) {
                    o = j.i$b._inner[m + 1];
                    u = j.i$d(o);
                    if (u - p > l) {
                        break;
                    }
                    m++;
                    s += this.rw._inner[m];
                    t += this.rx._inner[m];
                    v++;
                }
                s /= v;
                t /= v;
                var w = s - t * this.r0;
                var x = s;
                var y = s + t * this.r0;
                var z = NaN;
                if (!isNaN_(p)) {
                    z = this.oh.dz(p, h);
                }
                n = [z, w, x, y];
            }
            var aa = Math.max(1, l);
            if (!isNaN_(n[0]) && m * aa >= this.rs) {
                if (this.oh != null && typeCast(ISortingAxis_$type, this.oh) !== null) {
                    n[0] = n[0] + k;
                }
                else {
                    n[0] = f.dz(n[0], h) + k;
                }
                n[1] = g.dz(n[1], i);
                n[2] = g.dz(n[2], i);
                n[3] = g.dz(n[3], i);
                a.f.add(n);
            }
        }
    };
    BollingerBandsOverlay.prototype.jl = function (a, b) {
        _super.prototype.jl.call(this, a, b);
        var c = b;
        if (c != null) {
            c.b4();
        }
    };
    BollingerBandsOverlay.prototype.fh = function (a, b, c) {
        if (this.rw == null) {
            return _super.prototype.fh.call(this, a, b, c);
        }
        var d = this.getEffectiveViewport1(this.bs);
        var e = this.p7(this.bs.bv, this.bs.bu, d);
        var f = new ScalerParams(0, this.bs.bv, this.bs.bu, this.oh.ca, d);
        f.c = this.b6.o7;
        return this.fj(this.rw, a, this.oh, f, e, runOn(this, this.p6), b, c);
    };
    BollingerBandsOverlay.prototype.gf = function (a, b) {
        if (this.rw == null) {
            return _super.prototype.gf.call(this, a, b);
        }
        return this.gg(a, b, this.oh, runOn(this, this.p6), this.rw);
    };
    BollingerBandsOverlay.prototype.gd = function (a, b) {
        if (this.rw == null) {
            return _super.prototype.gd.call(this, a, b);
        }
        return this.ge(a, b, this.oh, runOn(this, this.p6), this.rw);
    };
    BollingerBandsOverlay.prototype.ec = function (a, b, c) {
        var d = _super.prototype.ec.call(this, a, b, c);
        if (!this.pp(this.pz())) {
            d = false;
        }
        return d;
    };
    BollingerBandsOverlay.prototype.q9 = function (a, b) {
        _super.prototype.q9.call(this, a, b);
        var c = typeCast(BollingerBandsOverlayView.$, b);
        var d = this.getEffectiveViewport1(b);
        if (b.b0(a)) {
            c.b4();
            var e_1 = a.f.count;
            var f = function (g) { return a.f._inner[g][0]; };
            var g = function (h) { return a.f._inner[e_1 - 1 - h][0]; };
            var h = function (i) { return a.f._inner[i][1]; };
            var i = function (j) { return a.f._inner[j][2]; };
            var j = function (k) { return a.f._inner[e_1 - 1 - k][3]; };
            c.b5(e_1, f, g, h, i, j);
            b.b2(a);
        }
        this.op.a0(this, this.po(), runOn(this, this.n9), this.qd(b), this.qf(b));
        var k = false;
        var l = this.op.b;
        var m = a.f;
        var n = this.cd.count;
        if (l != null) {
            k = true;
        }
        if (k) {
            var o = new ScalerParams(0, b.bv, b.bu, this.oh.ca, d);
            this.q6(m, -1, n, this.oh, o, b.q);
        }
        var p = c.cc;
        var q = c.cd;
        var r = c.ce;
        var s = c.b7;
        this.op.ad(q, true, false, true, true);
        this.op.an = null;
        this.op.am = null;
        this.op.ad(p, true, false, false, true);
        this.op.ad(r, true, false, false, true);
        this.op.ad(s, false, true, false, false);
        s._opacity = this.op.j * this.er;
    };
    BollingerBandsOverlay.prototype.bp = function () {
        return new BollingerBandsOverlayView(this);
    };
    BollingerBandsOverlay.prototype.kk = function (a) {
        _super.prototype.kk.call(this, a);
        this.rv = typeCast(BollingerBandsOverlayView.$, a);
    };
    BollingerBandsOverlay.prototype.qg = function () {
        return 3;
    };
    BollingerBandsOverlay.prototype.fa = function () {
        return Series.fb(this.rw, null);
    };
    BollingerBandsOverlay.$t = markType(BollingerBandsOverlay, 'BollingerBandsOverlay', FinancialOverlay.$);
    BollingerBandsOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, BollingerBandsOverlay, 'raisePropertyChanged', ['Multiplier:r0:r4', [1, 2], 'Period:r1:r5', [1, 14]]);
    return BollingerBandsOverlay;
}(FinancialOverlay));
export { BollingerBandsOverlay };
/**
 * @hidden
 */
var BollingerBandsBucketCalculator = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(BollingerBandsBucketCalculator, _super);
    function BollingerBandsBucketCalculator(a) {
        var _this = _super.call(this, a) || this;
        _this.f = null;
        _this.f = a;
        return _this;
    }
    BollingerBandsBucketCalculator.prototype.getBucket = function (a) {
        var b = a * this.b;
        var c = Math.min(b + this.b - 1, this.a.bz.cd.count - 1);
        if (b <= c) {
            var d = this.f.b3.r0;
            var e = 0;
            var f = 0;
            var g = 0;
            for (var h = b; h <= c; ++h) {
                if (!isNaN_(this.f.b3.rw._inner[h]) && !isNaN_(this.f.b3.rx._inner[h])) {
                    e += this.f.b3.rw._inner[h];
                    f += this.f.b3.rx._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 = markType(BollingerBandsBucketCalculator, 'BollingerBandsBucketCalculator', FinancialBucketCalculator.$);
    return BollingerBandsBucketCalculator;
}(FinancialBucketCalculator));
export { BollingerBandsBucketCalculator };
/**
 * @hidden
 */
var BollingerBandsOverlayView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(BollingerBandsOverlayView, _super);
    function BollingerBandsOverlayView(a) {
        var _this = _super.call(this, a) || this;
        _this.b3 = null;
        _this.b8 = new Polygon();
        _this.cf = new Polyline();
        _this.cg = new Polyline();
        _this.ch = new Polyline();
        _this.b6 = new Polygon();
        _this.b9 = new Polyline();
        _this.ca = new Polyline();
        _this.cb = new Polyline();
        _this.b3 = a;
        return _this;
    }
    BollingerBandsOverlayView.prototype.as = function () {
        _super.prototype.as.call(this);
        if (!this.q) {
            this.e.bx = 1;
        }
    };
    BollingerBandsOverlayView.prototype.by = function () {
        return new BollingerBandsBucketCalculator(this);
    };
    BollingerBandsOverlayView.prototype.b5 = function (a, b, c, d, e, f) {
        var e_2, _a, e_3, _b, e_4, _c;
        try {
            for (var _d = tslib_1.__values(fromEnum(Flattener.d(a, b, d, this.e.fq))), _e = _d.next(); !_e.done; _e = _d.next()) {
                var g = _e.value;
                this.b8.ak.add({ $type: Point_$type, x: b(g), y: d(g) });
                this.cf.ak.add({ $type: Point_$type, x: b(g), y: d(g) });
            }
        }
        catch (e_2_1) {
            e_2 = { error: e_2_1 };
        }
        finally {
            try {
                if (_e && !_e.done && (_a = _d.return))
                    _a.call(_d);
            }
            finally {
                if (e_2)
                    throw e_2.error;
            }
        }
        try {
            for (var _f = tslib_1.__values(fromEnum(Flattener.d(a, b, e, this.e.fq))), _g = _f.next(); !_g.done; _g = _f.next()) {
                var h = _g.value;
                this.cg.ak.add({ $type: Point_$type, x: b(h), y: e(h) });
            }
        }
        catch (e_3_1) {
            e_3 = { error: e_3_1 };
        }
        finally {
            try {
                if (_g && !_g.done && (_b = _f.return))
                    _b.call(_f);
            }
            finally {
                if (e_3)
                    throw e_3.error;
            }
        }
        try {
            for (var _h = tslib_1.__values(fromEnum(Flattener.d(a, c, f, this.e.fq))), _j = _h.next(); !_j.done; _j = _h.next()) {
                var i = _j.value;
                this.b8.ak.add({ $type: Point_$type, x: c(i), y: f(i) });
                this.ch.ak.add({ $type: Point_$type, x: c(i), y: f(i) });
            }
        }
        catch (e_4_1) {
            e_4 = { error: e_4_1 };
        }
        finally {
            try {
                if (_j && !_j.done && (_c = _h.return))
                    _c.call(_h);
            }
            finally {
                if (e_4)
                    throw e_4.error;
            }
        }
        this.aq();
    };
    BollingerBandsOverlayView.prototype.b4 = function () {
        this.b8.ak.clear();
        this.cf.ak.clear();
        this.cg.ak.clear();
        this.ch.ak.clear();
        this.aq();
    };
    Object.defineProperty(BollingerBandsOverlayView.prototype, "b7", {
        get: function () {
            return this.b8;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BollingerBandsOverlayView.prototype, "cc", {
        get: function () {
            return this.cf;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BollingerBandsOverlayView.prototype, "cd", {
        get: function () {
            return this.cg;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BollingerBandsOverlayView.prototype, "ce", {
        get: function () {
            return this.ch;
        },
        enumerable: true,
        configurable: true
    });
    BollingerBandsOverlayView.prototype.bc = function () {
        _super.prototype.bc.call(this);
        this.b6.ak = this.b8.ak;
        this.b9.ak = this.cf.ak;
        this.ca.ak = this.cg.ak;
        this.cb.ak = this.ch.ak;
        var 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;
        this.cb._stroke = a;
        this.cb.ac = this.e.eu + 3;
    };
    BollingerBandsOverlayView.prototype.a6 = function (a, b) {
        _super.prototype.a6.call(this, a, b);
        if (a.d) {
            if (b) {
                a.t(this.b6);
                a.u(this.b9);
                a.u(this.ca);
                a.u(this.cb);
            }
            else {
                a.t(this.b8);
                a.u(this.cf);
                a.u(this.cg);
                a.u(this.ch);
            }
        }
    };
    BollingerBandsOverlayView.prototype.al = function (a) {
        _super.prototype.al.call(this, a);
        this.e.a5.exportPolygonData(a, this.b8, "FillShape", ["Fill"]);
        this.e.a5.exportPolylineData(a, this.cf, "BottomLine", ["Lower", "Main"]);
        this.e.a5.exportPolylineData(a, this.cg, "CentralLine", ["Central"]);
        this.e.a5.exportPolylineData(a, this.ch, "TopLine", ["Upper"]);
    };
    BollingerBandsOverlayView.$t = markType(BollingerBandsOverlayView, 'BollingerBandsOverlayView', FinancialSeriesView.$);
    return BollingerBandsOverlayView;
}(FinancialSeriesView));
export { BollingerBandsOverlayView };
//# sourceMappingURL=BollingerBandsOverlay_combined.js.map
