/*
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.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);
        return _this;
    }
    PriceChannelOverlay.prototype.kp = function (a, b, c, d) {
        switch (b) {
            case "HighColumn":
            case "LowColumn":
                this.rq = false;
                break;
        }
        _super.prototype.kp.call(this, a, b, c, d);
        switch (b) {
            case PriceChannelOverlay.$$p[0]:
                this.rq = false;
                this.k3(false);
                break;
        }
    };
    PriceChannelOverlay.prototype.ec = function (a, b, c) {
        var d = _super.prototype.ec.call(this, a, b, c);
        if (this.pa == null || this.pb == null) {
            d = false;
        }
        return d;
    };
    PriceChannelOverlay.prototype.rr = function () {
        this.rx.clear();
        this.rw.clear();
        var a = truncate(MathUtil.b(this.ry, 0, this.cd.count));
        var b = Math.min(this.pa.count, this.pb.count);
        var c = this.p0(this.pa);
        var d = this.p0(this.pb);
        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.rx.add(g);
            this.rw.add(h);
        }
        return true;
    };
    PriceChannelOverlay.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 = new ScalerParams(0, c, d, this.oh.ca, e);
        var g = new ScalerParams(0, c, d, this.o2.ca, e);
        g.b = this.fa();
        var h = this.oh;
        var i = this.o2;
        a.f.clear();
        a.m.clear();
        a.p.clear();
        var j = 0;
        var 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();
        var l = this.oh.d2(2, f) - this.oh.d2(1, f);
        for (var m = b.bx.c; m <= b.bx.d; ++m) {
            var n = void 0;
            if (k == null) {
                n = b.bx.getBucket(m);
            }
            else {
                var o = k.i$b._inner[m];
                var p = k.i$d(o);
                var q = this.rx._inner[m];
                var r = this.rw._inner[m];
                var s = q;
                var t = r;
                var 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)) {
                    var v = NaN;
                    if (!isNaN_(p)) {
                        v = this.oh.dz(p, f);
                    }
                    n = [v, t, s];
                }
                else {
                    n = [NaN, NaN, NaN];
                }
            }
            var 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);
            }
        }
    };
    PriceChannelOverlay.prototype.jl = function (a, b) {
        _super.prototype.jl.call(this, a, b);
        var c = b;
        if (c != null) {
            c.b4();
        }
    };
    PriceChannelOverlay.prototype.q9 = function (a, b) {
        _super.prototype.q9.call(this, a, b);
        var c = typeCast(PriceChannelOverlayView.$, b);
        if (c == null) {
            return;
        }
        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[e_1 - 1 - j][2]; };
            c.b5(e_1, f, g, h, i);
            b.b2(a);
        }
        this.op.a0(this, this.po(), runOn(this, this.n9), this.qd(b), this.qf(b));
        var j = false;
        var k = this.op.b;
        var l = a.f;
        var m = this.cd.count;
        if (k != null) {
            j = true;
        }
        if (j) {
            var n = new ScalerParams(0, b.bv, b.bu, this.oh.ca, d);
            this.q6(l, -1, m, this.oh, n, b.q);
        }
        var o = c.cb;
        var p = c.cc;
        var 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;
    };
    PriceChannelOverlay.prototype.bp = function () {
        return new PriceChannelOverlayView(this);
    };
    PriceChannelOverlay.prototype.kk = function (a) {
        _super.prototype.kk.call(this, a);
        this.rv = typeCast(PriceChannelOverlayView.$, a);
    };
    PriceChannelOverlay.prototype.fh = function (a, b, c) {
        if (this.b6 == null) {
            return NaN;
        }
        var d = this.getEffectiveViewport1(this.bs);
        var e = new ScalerParams(0, this.b6.os, this.bs.bu, this.oh.ca, d);
        var 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);
    };
    PriceChannelOverlay.prototype.gd = function (a, b) {
        if (this.rx == null || this.rw == null) {
            return _super.prototype.gd.call(this, a, b);
        }
        return this.ge(a, b, this.oh, runOn(this, this.p6), new RangeValueList(this.rx, this.rw));
    };
    PriceChannelOverlay.prototype.gf = function (a, b) {
        if (this.rx == null || this.rw == null) {
            return _super.prototype.gf.call(this, a, b);
        }
        return this.gg(a, b, this.oh, runOn(this, this.p6), new RangeValueList(this.rx, this.rw));
    };
    PriceChannelOverlay.prototype.fa = function () {
        return Series.fb(this.rw, null);
    };
    PriceChannelOverlay.$t = markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:ry:r0', [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.bz.cd.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.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 = 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.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;
        return _this;
    }
    Object.defineProperty(PriceChannelOverlayView.prototype, "b7", {
        get: function () {
            return this.b8;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PriceChannelOverlayView.prototype, "cb", {
        get: function () {
            return this.cd;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PriceChannelOverlayView.prototype, "cc", {
        get: function () {
            return this.ce;
        },
        enumerable: true,
        configurable: true
    });
    PriceChannelOverlayView.prototype.as = function () {
        _super.prototype.as.call(this);
        if (!this.q) {
            this.e.bx = 1;
        }
    };
    PriceChannelOverlayView.prototype.by = function () {
        return new PriceChannelBucketCalculator(this);
    };
    PriceChannelOverlayView.prototype.b4 = function () {
        this.b8.ak.clear();
        this.cd.ak.clear();
        this.ce.ak.clear();
        this.aq();
    };
    PriceChannelOverlayView.prototype.b5 = 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.fq))), _d = _c.next(); !_d.done; _d = _c.next()) {
                var f = _d.value;
                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) });
            }
        }
        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.fq))), _f = _e.next(); !_f.done; _f = _e.next()) {
                var g = _f.value;
                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) });
            }
        }
        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.aq();
    };
    PriceChannelOverlayView.prototype.bc = function () {
        _super.prototype.bc.call(this);
        this.b6.ak = this.b8.ak;
        this.b9.ak = this.cd.ak;
        this.ca.ak = this.ce.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;
    };
    PriceChannelOverlayView.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);
            }
            else {
                a.t(this.b8);
                a.u(this.cd);
                a.u(this.ce);
            }
        }
    };
    PriceChannelOverlayView.prototype.al = function (a) {
        _super.prototype.al.call(this, 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 = markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
    return PriceChannelOverlayView;
}(FinancialSeriesView));
export { PriceChannelOverlayView };
//# sourceMappingURL=PriceChannelOverlay_combined.js.map
