/*
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, 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
 */
var PriceChannelOverlay = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(PriceChannelOverlay, _super);
    function PriceChannelOverlay() {
        var _this = _super.call(this) || this;
        _this.pz = new List$1(Number_$type, 0);
        _this.py = new List$1(Number_$type, 0);
        _this.ab = PriceChannelOverlay.$;
        _this.ml = new CategoryFrame(3);
        _this.mn = new CategoryFrame(3);
        _this.mk = new CategoryFrame(3);
        return _this;
    }
    PriceChannelOverlay.prototype.i7 = function (a, b, c, d) {
        switch (b) {
            case "HighColumn":
            case "LowColumn":
                this.ps = false;
                break;
        }
        _super.prototype.i7.call(this, a, b, c, d);
        switch (b) {
            case PriceChannelOverlay.$$p[0]:
                this.ps = false;
                this.jl(false);
                break;
        }
    };
    PriceChannelOverlay.prototype.dw = function (a, b, c) {
        var d = _super.prototype.dw.call(this, a, b, c);
        if (this.nb == null || this.nc == null) {
            d = false;
        }
        return d;
    };
    PriceChannelOverlay.prototype.pt = function () {
        this.pz.clear();
        this.py.clear();
        var a = truncate(MathUtil.b(this.p0, 0, this.bz.count));
        var b = Math.min(this.nb.count, this.nc.count);
        var c = this.n2(this.nb);
        var d = this.n2(this.nc);
        for (var e = 0; e < b; e++) {
            var f = Math.min(a, e);
            var g = -1.7976931348623157E+308;
            var h = 1.7976931348623157E+308;
            for (var 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.pz.add(g);
            this.py.add(h);
        }
        return true;
    };
    PriceChannelOverlay.prototype.o9 = function (a, b) {
        _super.prototype.o9.call(this, a, b);
        var c = b.bs;
        var d = b.br;
        var e = this.getEffectiveViewport1(b);
        var f = new ScalerParams(0, c, d, this.mi.ca, e);
        var g = new ScalerParams(0, c, d, this.m3.ca, e);
        g.b = this.eh();
        var h = this.mi;
        var i = this.m3;
        a.f.clear();
        a.m.clear();
        a.p.clear();
        var j = 0;
        var k = typeCast(ISortingAxis_$type, this.mi);
        if (k != null && k.i$b.count != this.bz.count) {
            return;
        }
        j = this.n9(c, d, e);
        if (!this.ps) {
            this.ps = this.pt();
        }
        g.b = this.eh();
        var l = this.mi.d1(2, f) - this.mi.d1(1, f);
        for (var m = b.bu.c; m <= b.bu.d; ++m) {
            var n = void 0;
            if (k == null) {
                n = b.bu.getBucket(m);
            }
            else {
                var o = k.i$b._inner[m];
                var p = k.i$d(o);
                var q = this.pz._inner[m];
                var r = this.py._inner[m];
                var s = q;
                var t = r;
                var u = p;
                while (m < b.bu.d) {
                    o = k.i$b._inner[m + 1];
                    u = k.i$d(o);
                    if (u - p > l) {
                        break;
                    }
                    m++;
                    s = Math.max(q, this.pz._inner[m]);
                    t = Math.min(r, this.py._inner[m]);
                }
                if (!isInfinity(t) && !isInfinity(s)) {
                    var v = NaN;
                    if (!isNaN_(p)) {
                        v = this.mi.dy(p, f);
                    }
                    n = [v, t, s];
                }
                else {
                    n = [NaN, NaN, NaN];
                }
            }
            var w = Math.max(1, l);
            if (!isNaN_(n[0]) && m * w >= this.pu) {
                if (this.mi != null && typeCast(ISortingAxis_$type, this.mi) !== null) {
                    n[0] = n[0] + j;
                }
                else {
                    n[0] = h.dy(n[0], f) + j;
                }
                n[1] = i.dy(n[1], g);
                n[2] = i.dy(n[2], g);
                a.f.add(n);
            }
        }
    };
    PriceChannelOverlay.prototype.h3 = function (a, b) {
        _super.prototype.h3.call(this, a, b);
        var c = b;
        if (c != null) {
            c.b1();
        }
    };
    PriceChannelOverlay.prototype.pb = function (a, b) {
        _super.prototype.pb.call(this, a, b);
        var c = typeCast(PriceChannelOverlayView.$, b);
        if (c == null) {
            return;
        }
        var d = this.getEffectiveViewport1(b);
        if (b.bx(a)) {
            c.b1();
            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[e_1 - 1 - j][2]; };
            c.b2(e_1, f, g, h, i);
            b.bz(a);
        }
        this.mq.x(this, this.nq(), this.mi, runOn(this, this.ma), this.of(b), this.oh(b));
        var j = false;
        var k = this.mq.c;
        var l = a.f;
        var m = this.bz.count;
        if (k != null) {
            j = true;
        }
        if (j) {
            var n = new ScalerParams(0, b.bs, b.br, this.mi.ca, d);
            this.o8(l, -1, m, this.mi, n, b.n);
        }
        var o = c.b8;
        var p = c.b9;
        var q = c.b4;
        this.mq.ae(o, true, false, true, true);
        this.mq.ae(p, true, false, true, true);
        this.mq.ae(q, false, true, false, false);
        q._opacity = this.mq.i * this.d6;
    };
    PriceChannelOverlay.prototype.bf = function () {
        return new PriceChannelOverlayView(this);
    };
    PriceChannelOverlay.prototype.i2 = function (a) {
        _super.prototype.i2.call(this, a);
        this.px = typeCast(PriceChannelOverlayView.$, a);
    };
    PriceChannelOverlay.prototype.en = function (a, b, c) {
        if (this.bs == null) {
            return NaN;
        }
        var d = this.getEffectiveViewport1(this.bi);
        var e = new ScalerParams(0, this.bs.n2, this.bi.br, this.mi.ca, d);
        var f = this.n9(this.bs.n2, this.bi.br, d);
        return this.ep(new RangeValueList(this.pz, this.py), a, this.mi, e, f, runOn(this, this.n8), b, c);
    };
    PriceChannelOverlay.prototype.fc = function (a, b) {
        if (this.pz == null || this.py == null) {
            return _super.prototype.fc.call(this, a, b);
        }
        return this.fd(a, b, this.mi, runOn(this, this.n8), new RangeValueList(this.pz, this.py));
    };
    PriceChannelOverlay.prototype.fe = function (a, b) {
        if (this.pz == null || this.py == null) {
            return _super.prototype.fe.call(this, a, b);
        }
        return this.ff(a, b, this.mi, runOn(this, this.n8), new RangeValueList(this.pz, this.py));
    };
    PriceChannelOverlay.prototype.eh = function () {
        return Series.ei(this.py, null);
    };
    PriceChannelOverlay.$t = markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:p0:p2', [1, 14]]);
    return PriceChannelOverlay;
}(FinancialOverlay));
export { PriceChannelOverlay };
/**
 * @hidden
 */
var PriceChannelBucketCalculator = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(PriceChannelBucketCalculator, _super);
    function PriceChannelBucketCalculator(a) {
        var _this = _super.call(this, a) || this;
        _this.f = null;
        _this.f = a;
        return _this;
    }
    PriceChannelBucketCalculator.prototype.getBucket = function (a) {
        var b = a * this.b;
        var c = Math.min(b + this.b - 1, this.a.bw.bz.count - 1);
        if (b <= c) {
            var d = -1.7976931348623157E+308;
            var e = 1.7976931348623157E+308;
            var f = 0;
            for (var g = b; g <= c; ++g) {
                if (!isNaN_(this.f.b0.pz._inner[g]) && !isNaN_(this.f.b0.py._inner[g])) {
                    d = Math.max(d, this.f.b0.pz._inner[g]);
                    e = Math.min(e, this.f.b0.py._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 = markType(PriceChannelBucketCalculator, 'PriceChannelBucketCalculator', FinancialBucketCalculator.$);
    return PriceChannelBucketCalculator;
}(FinancialBucketCalculator));
export { PriceChannelBucketCalculator };
/**
 * @hidden
 */
var PriceChannelOverlayView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(PriceChannelOverlayView, _super);
    function PriceChannelOverlayView(a) {
        var _this = _super.call(this, a) || this;
        _this.b5 = new Polygon();
        _this.ca = new Polyline();
        _this.cb = new Polyline();
        _this.b0 = null;
        _this.b3 = new Polygon();
        _this.b6 = new Polyline();
        _this.b7 = new Polyline();
        _this.b0 = a;
        return _this;
    }
    Object.defineProperty(PriceChannelOverlayView.prototype, "b4", {
        get: function () {
            return this.b5;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PriceChannelOverlayView.prototype, "b8", {
        get: function () {
            return this.ca;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PriceChannelOverlayView.prototype, "b9", {
        get: function () {
            return this.cb;
        },
        enumerable: true,
        configurable: true
    });
    PriceChannelOverlayView.prototype.ap = function () {
        _super.prototype.ap.call(this);
        if (!this.n) {
            this.e.bj = 1;
        }
    };
    PriceChannelOverlayView.prototype.bv = function () {
        return new PriceChannelBucketCalculator(this);
    };
    PriceChannelOverlayView.prototype.b1 = function () {
        this.b5.ak.clear();
        this.ca.ak.clear();
        this.cb.ak.clear();
        this.an();
    };
    PriceChannelOverlayView.prototype.b2 = function (a, b, c, d, e) {
        var e_2, _a, e_3, _b;
        try {
            for (var _c = tslib_1.__values(fromEnum(Flattener.d(a, b, d, this.e.eu))), _d = _c.next(); !_d.done; _d = _c.next()) {
                var f = _d.value;
                this.b5.ak.add({ $type: Point_$type, x: b(f), y: d(f) });
                this.ca.ak.add({ $type: Point_$type, x: b(f), y: d(f) });
            }
        }
        catch (e_2_1) {
            e_2 = { error: e_2_1 };
        }
        finally {
            try {
                if (_d && !_d.done && (_a = _c.return))
                    _a.call(_c);
            }
            finally {
                if (e_2)
                    throw e_2.error;
            }
        }
        try {
            for (var _e = tslib_1.__values(fromEnum(Flattener.d(a, c, e, this.e.eu))), _f = _e.next(); !_f.done; _f = _e.next()) {
                var g = _f.value;
                this.b5.ak.add({ $type: Point_$type, x: c(g), y: e(g) });
                this.cb.ak.add({ $type: Point_$type, x: c(g), y: e(g) });
            }
        }
        catch (e_3_1) {
            e_3 = { error: e_3_1 };
        }
        finally {
            try {
                if (_f && !_f.done && (_b = _e.return))
                    _b.call(_e);
            }
            finally {
                if (e_3)
                    throw e_3.error;
            }
        }
        this.an();
    };
    PriceChannelOverlayView.prototype.a9 = function () {
        _super.prototype.a9.call(this);
        this.b3.ak = this.b5.ak;
        this.b6.ak = this.ca.ak;
        this.b7.ak = this.cb.ak;
        var 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;
    };
    PriceChannelOverlayView.prototype.a3 = function (a, b) {
        _super.prototype.a3.call(this, a, b);
        if (a.d) {
            if (b) {
                a.t(this.b3);
                a.u(this.b6);
                a.u(this.b7);
            }
            else {
                a.t(this.b5);
                a.u(this.ca);
                a.u(this.cb);
            }
        }
    };
    PriceChannelOverlayView.prototype.ai = function (a) {
        _super.prototype.ai.call(this, a);
        this.e.a2.exportPolygonData(a, this.b5, "fill", ["Fill"]);
        this.e.a2.exportPolylineData(a, this.ca, "bottom", ["Lower", "Main"]);
        this.e.a2.exportPolylineData(a, this.cb, "top", ["Upper"]);
    };
    PriceChannelOverlayView.$t = markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
    return PriceChannelOverlayView;
}(FinancialSeriesView));
export { PriceChannelOverlayView };
//# sourceMappingURL=PriceChannelOverlay_combined.js.map
