/*
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-angular-core";
import { List$1 } from "igniteui-angular-core";
import { Number_$type, typeCast, runOn, markType, markDep, Point_$type, fromEnum } from "igniteui-angular-core";
import { CategoryFrame } from "./CategoryFrame";
import { Series } from "./Series";
import { MathUtil } from "igniteui-angular-core";
import { FinancialSeriesView } from "./FinancialSeriesView";
import { ScalerParams } from "./ScalerParams";
import { ISortingAxis_$type } from "./ISortingAxis";
import { FinancialBucketCalculator } from "./FinancialBucketCalculator";
import { Polyline } from "igniteui-angular-core";
import { Polygon } from "igniteui-angular-core";
import { RangeValueList } from "./RangeValueList";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_, isInfinity } from "igniteui-angular-core";
import { Flattener } from "igniteui-angular-core";
/**
 * @hidden
 */
var PriceChannelOverlay = /** @class */ (function (_super) {
    tslib_1.__extends(PriceChannelOverlay, _super);
    function PriceChannelOverlay() {
        var _this = _super.call(this) || this;
        _this.pp = new List$1(Number_$type, 0);
        _this.po = new List$1(Number_$type, 0);
        _this.ab = PriceChannelOverlay.$;
        _this.mb = new CategoryFrame(3);
        _this.md = new CategoryFrame(3);
        _this.ma = new CategoryFrame(3);
        return _this;
    }
    PriceChannelOverlay.prototype.iz = function (a, b, c, d) {
        switch (b) {
            case "HighColumn":
            case "LowColumn":
                this.pi = false;
                break;
        }
        _super.prototype.iz.call(this, a, b, c, d);
        switch (b) {
            case PriceChannelOverlay.$$p[0]:
                this.pi = false;
                this.jd(false);
                break;
        }
    };
    PriceChannelOverlay.prototype.dw = function (a, b, c) {
        var d = _super.prototype.dw.call(this, a, b, c);
        if (this.my == null || this.m0 == null) {
            d = false;
        }
        return d;
    };
    PriceChannelOverlay.prototype.pj = function () {
        this.pp.clear();
        this.po.clear();
        var a = truncate(MathUtil.b(this.pq, 0, this.bz.count));
        var b = Math.min(this.my.count, this.m0.count);
        var c = this.ns(this.my);
        var d = this.ns(this.m0);
        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.pp.add(g);
            this.po.add(h);
        }
        return true;
    };
    PriceChannelOverlay.prototype.oz = function (a, b) {
        _super.prototype.oz.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.l8.b8, e);
        var g = new ScalerParams(0, c, d, this.mt.b8, e);
        g.b = this.eh();
        var h = this.l8;
        var i = this.mt;
        a.f.clear();
        a.m.clear();
        a.p.clear();
        var j = 0;
        var k = typeCast(ISortingAxis_$type, this.l8);
        if (k != null && k.i$b.count != this.bz.count) {
            return;
        }
        j = this.nz(c, d, e);
        if (!this.pi) {
            this.pi = this.pj();
        }
        g.b = this.eh();
        var l = this.l8.dz(2, f) - this.l8.dz(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.pp._inner[m];
                var r = this.po._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.pp._inner[m]);
                    t = Math.min(r, this.po._inner[m]);
                }
                if (!isInfinity(t) && !isInfinity(s)) {
                    var v = NaN;
                    if (!isNaN_(p)) {
                        v = this.l8.dw(p, f);
                    }
                    n = [v, t, s];
                }
                else {
                    n = [NaN, NaN, NaN];
                }
            }
            var w = Math.max(1, l);
            if (!isNaN_(n[0]) && m * w >= this.pk) {
                if (this.l8 != null && typeCast(ISortingAxis_$type, this.l8) !== null) {
                    n[0] = n[0] + j;
                }
                else {
                    n[0] = h.dw(n[0], f) + j;
                }
                n[1] = i.dw(n[1], g);
                n[2] = i.dw(n[2], g);
                a.f.add(n);
            }
        }
    };
    PriceChannelOverlay.prototype.hv = function (a, b) {
        _super.prototype.hv.call(this, a, b);
        var c = b;
        if (c != null) {
            c.b1();
        }
    };
    PriceChannelOverlay.prototype.o1 = function (a, b) {
        _super.prototype.o1.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.mg.x(this, this.ng(), this.l8, runOn(this, this.l0), this.n5(b), this.n7(b));
        var j = false;
        var k = this.mg.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.l8.b8, d);
            this.oy(l, -1, m, this.l8, n, b.n);
        }
        var o = c.b8;
        var p = c.b9;
        var q = c.b4;
        this.mg.ae(o, true, false, true, true);
        this.mg.ae(p, true, false, true, true);
        this.mg.ae(q, false, true, false, false);
        q._opacity = this.mg.i * this.d6;
    };
    PriceChannelOverlay.prototype.bf = function () {
        return new PriceChannelOverlayView(this);
    };
    PriceChannelOverlay.prototype.iu = function (a) {
        _super.prototype.iu.call(this, a);
        this.pn = 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.mq, this.bi.br, this.l8.b8, d);
        var f = this.nz(this.bs.mq, this.bi.br, d);
        return this.ep(new RangeValueList(this.pp, this.po), a, this.l8, e, f, runOn(this, this.ny), b, c);
    };
    PriceChannelOverlay.prototype.fc = function (a, b) {
        if (this.pp == null || this.po == null) {
            return _super.prototype.fc.call(this, a, b);
        }
        return this.fd(a, b, this.l8, runOn(this, this.ny), new RangeValueList(this.pp, this.po));
    };
    PriceChannelOverlay.prototype.fe = function (a, b) {
        if (this.pp == null || this.po == null) {
            return _super.prototype.fe.call(this, a, b);
        }
        return this.ff(a, b, this.l8, runOn(this, this.ny), new RangeValueList(this.pp, this.po));
    };
    PriceChannelOverlay.prototype.eh = function () {
        return Series.ei(this.po, null);
    };
    PriceChannelOverlay.$t = markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:pq:ps', [1, 14]]);
    return PriceChannelOverlay;
}(FinancialOverlay));
export { PriceChannelOverlay };
/**
 * @hidden
 */
var PriceChannelBucketCalculator = /** @class */ (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.pp._inner[g]) && !isNaN_(this.f.b0.po._inner[g])) {
                    d = Math.max(d, this.f.b0.pp._inner[g]);
                    e = Math.min(e, this.f.b0.po._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 */ (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