/*
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 { __extends, __values } from "tslib";
import { FinancialOverlay } from "./FinancialOverlay";
import { DependencyProperty } from "igniteui-angular-core";
import { Series } from "./Series";
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 { 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 */ /*@__PURE__*/ (function (_super) {
    __extends(PriceChannelOverlay, _super);
    function PriceChannelOverlay() {
        var _this = _super.call(this) || this;
        _this.aa5 = new List$1(Number_$type, 0);
        _this.aa4 = new List$1(Number_$type, 0);
        _this.ab = PriceChannelOverlay.$;
        _this.w8 = new CategoryFrame(3);
        _this.xa = new CategoryFrame(3);
        _this.w6 = new CategoryFrame(3);
        return _this;
    }
    PriceChannelOverlay.prototype.bj = function () {
        return new PriceChannelOverlay();
    };
    PriceChannelOverlay.prototype.q7 = function (a, b, c, d) {
        switch (b) {
            case "HighColumn":
            case "LowColumn":
                this.aay = false;
                break;
        }
        _super.prototype.q7.call(this, a, b, c, d);
        switch (b) {
            case PriceChannelOverlay.$$p[0]:
                this.aay = false;
                this.rp(false);
                break;
        }
    };
    PriceChannelOverlay.prototype.he = function (a, b, c) {
        var d = _super.prototype.he.call(this, a, b, c);
        if (this.xy == null || this.xz == null) {
            d = false;
        }
        return d;
    };
    PriceChannelOverlay.prototype.aaz = function () {
        this.aa5.clear();
        this.aa4.clear();
        var a = truncate(MathUtil.d(this.aa6, 0, this.dn.count));
        var b = Math.min(this.xy.count, this.xz.count);
        var c = this.yo(this.xy);
        var d = this.yo(this.xz);
        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.aa5.add(g);
            this.aa4.add(h);
        }
        return true;
    };
    PriceChannelOverlay.prototype.aaa = function (a, b) {
        _super.prototype.aaa.call(this, a, b);
        var c = b.by;
        var d = b.bx;
        var e = this.getEffectiveViewport1(b);
        var f = new ScalerParams(0, c, d, this.w4.ch, e);
        var g = new ScalerParams(0, c, d, this.xn.ch, e);
        g.b = this.iy();
        var h = this.w4;
        var i = this.xn;
        a.f.clear();
        a.n.clear();
        a.q.clear();
        var j = 0;
        var k = typeCast(ISortingAxis_$type, this.w4);
        if (k != null && k.i$b.count != this.dn.count) {
            return;
        }
        j = this.yv(c, d, e);
        if (!this.aay) {
            this.aay = this.aaz();
        }
        g.b = this.iy();
        var l = this.w4.eo(2, f) - this.w4.eo(1, f);
        for (var m = b.b0.c; m <= b.b0.d; ++m) {
            var n = void 0;
            if (k == null) {
                n = b.b0.getBucket(m);
            }
            else {
                var o = k.i$b._inner[m];
                var p = k.i$d(o);
                var q = this.aa5._inner[m];
                var r = this.aa4._inner[m];
                var s = q;
                var t = r;
                var u = p;
                while (m < b.b0.d) {
                    o = k.i$b._inner[m + 1];
                    u = k.i$d(o);
                    if (u - p > l) {
                        break;
                    }
                    m++;
                    s = Math.max(q, this.aa5._inner[m]);
                    t = Math.min(r, this.aa4._inner[m]);
                }
                if (!isInfinity(t) && !isInfinity(s)) {
                    var v = NaN;
                    if (!isNaN_(p)) {
                        v = this.w4.el(p, f);
                    }
                    n = [v, t, s];
                }
                else {
                    n = [NaN, NaN, NaN];
                }
            }
            var w = Math.max(1, l);
            if (!isNaN_(n[0]) && m * w >= this.aa0) {
                if (this.w4 != null && typeCast(ISortingAxis_$type, this.w4) !== null) {
                    n[0] = n[0] + j;
                }
                else {
                    n[0] = h.el(n[0], f) + j;
                }
                n[1] = i.el(n[1], g);
                n[2] = i.el(n[2], g);
                a.f.add(n);
            }
        }
    };
    PriceChannelOverlay.prototype.o5 = function (a, b) {
        _super.prototype.o5.call(this, a, b);
        var c = b;
        if (c != null) {
            c.b7();
        }
    };
    PriceChannelOverlay.prototype.aac = function (a, b) {
        _super.prototype.aac.call(this, a, b);
        var c = typeCast(PriceChannelOverlayView.$, b);
        if (c == null) {
            return;
        }
        var d = this.getEffectiveViewport1(b);
        if (b.b3(a)) {
            c.b7();
            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.b8(e_1, f, g, h, i);
            b.b5(a);
        }
        this.xd.a2(this, this.yc(), runOn(this, this.ww), this.y1(b), this.y3(b));
        var j = false;
        var k = this.xd.b;
        var l = a.f;
        var m = this.dn.count;
        if (k != null) {
            j = true;
        }
        if (j) {
            var n = new ScalerParams(0, b.by, b.bx, this.w4.ch, d);
            this.z9(l, -1, m, this.w4, n, b.q, -1);
        }
        var o = c.ce;
        var p = c.cf;
        var q = c.ca;
        this.xd.ad(o, true, false, true, true);
        this.xd.ad(p, true, false, true, true);
        this.xd.ad(q, false, true, false, false);
        q._opacity = this.xd.j * this.h9;
    };
    PriceChannelOverlay.prototype.cs = function () {
        return new PriceChannelOverlayView(this);
    };
    PriceChannelOverlay.prototype.qz = function (a) {
        _super.prototype.qz.call(this, a);
        this.aa3 = typeCast(PriceChannelOverlayView.$, a);
    };
    PriceChannelOverlay.prototype.i5 = function (a, b, c) {
        if (this.db == null) {
            return NaN;
        }
        var d = this.getEffectiveViewport1(this.cv);
        var e = new ScalerParams(0, this.db.v4, this.cv.bx, this.w4.ch, d);
        var f = this.yv(this.db.v4, this.cv.bx, d);
        return this.i7(new RangeValueList(this.aa5, this.aa4), a, this.w4, e, f, runOn(this, this.yu), b, c);
    };
    PriceChannelOverlay.prototype.j8 = function (a, b) {
        if (this.aa5 == null || this.aa4 == null) {
            return _super.prototype.j8.call(this, a, b);
        }
        return this.j9(a, b, this.w4, runOn(this, this.yu), new RangeValueList(this.aa5, this.aa4));
    };
    PriceChannelOverlay.prototype.ka = function (a, b) {
        if (this.aa5 == null || this.aa4 == null) {
            return _super.prototype.ka.call(this, a, b);
        }
        return this.kb(a, b, this.w4, runOn(this, this.yu), new RangeValueList(this.aa5, this.aa4));
    };
    PriceChannelOverlay.prototype.iy = function () {
        return Series.i0(this.aa4, null);
    };
    PriceChannelOverlay.$t = markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:aa6:aa8', [1, 14]]);
    return PriceChannelOverlay;
}(FinancialOverlay));
export { PriceChannelOverlay };
/**
 * @hidden
 */
var PriceChannelBucketCalculator = /** @class */ /*@__PURE__*/ (function (_super) {
    __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.b2.dn.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.b6.aa5._inner[g]) && !isNaN_(this.f.b6.aa4._inner[g])) {
                    d = Math.max(d, this.f.b6.aa5._inner[g]);
                    e = Math.min(e, this.f.b6.aa4._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) {
    __extends(PriceChannelOverlayView, _super);
    function PriceChannelOverlayView(a) {
        var _this = _super.call(this, a) || this;
        _this.cb = new Polygon();
        _this.cg = new Polyline();
        _this.ch = new Polyline();
        _this.b6 = null;
        _this.b9 = new Polygon();
        _this.cc = new Polyline();
        _this.cd = new Polyline();
        _this.b6 = a;
        return _this;
    }
    Object.defineProperty(PriceChannelOverlayView.prototype, "ca", {
        get: function () {
            return this.cb;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PriceChannelOverlayView.prototype, "ce", {
        get: function () {
            return this.cg;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PriceChannelOverlayView.prototype, "cf", {
        get: function () {
            return this.ch;
        },
        enumerable: false,
        configurable: true
    });
    PriceChannelOverlayView.prototype.au = function () {
        _super.prototype.au.call(this);
        if (!this.q) {
        }
    };
    PriceChannelOverlayView.prototype.b1 = function () {
        return new PriceChannelBucketCalculator(this);
    };
    PriceChannelOverlayView.prototype.b7 = function () {
        this.cb.an.clear();
        this.cg.an.clear();
        this.ch.an.clear();
        this.as();
    };
    PriceChannelOverlayView.prototype.b8 = function (a, b, c, d, e) {
        var e_2, _a, e_3, _b;
        try {
            for (var _c = __values(fromEnum(Flattener.d(a, b, d, this.e.id))), _d = _c.next(); !_d.done; _d = _c.next()) {
                var f = _d.value;
                this.cb.an.add({ $type: Point_$type, x: b(f), y: d(f) });
                this.cg.an.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 = __values(fromEnum(Flattener.d(a, c, e, this.e.id))), _f = _e.next(); !_f.done; _f = _e.next()) {
                var g = _f.value;
                this.cb.an.add({ $type: Point_$type, x: c(g), y: e(g) });
                this.ch.an.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.as();
    };
    PriceChannelOverlayView.prototype.be = function () {
        _super.prototype.be.call(this);
        this.b9.an = this.cb.an;
        this.cc.an = this.cg.an;
        this.cd.an = this.ch.an;
        var a = this.br();
        this.b9._fill = a;
        this.b9._opacity = 1;
        this.cc._stroke = a;
        this.cc.ad = this.e.ie + 3;
        this.cd._stroke = a;
        this.cd.ad = this.e.ie + 3;
    };
    PriceChannelOverlayView.prototype.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        if (a.d) {
            if (b) {
                a.u(this.b9);
                a.v(this.cc);
                a.v(this.cd);
            }
            else {
                a.u(this.cb);
                a.v(this.cg);
                a.v(this.ch);
            }
        }
    };
    PriceChannelOverlayView.prototype.an = function (a) {
        _super.prototype.an.call(this, a);
        this.e.bc.exportPolygonData(a, this.cb, "fill", ["Fill"]);
        this.e.bc.exportPolylineData(a, this.cg, "bottom", ["Lower", "Main"]);
        this.e.bc.exportPolylineData(a, this.ch, "top", ["Upper"]);
    };
    PriceChannelOverlayView.$t = markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
    return PriceChannelOverlayView;
}(FinancialSeriesView));
export { PriceChannelOverlayView };
