/*
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.abh = new List$1(Number_$type, 0);
        _this.abg = new List$1(Number_$type, 0);
        _this.ab = PriceChannelOverlay.$;
        _this.xk = new CategoryFrame(3);
        _this.xm = new CategoryFrame(3);
        _this.xi = new CategoryFrame(3);
        return _this;
    }
    PriceChannelOverlay.prototype.bk = function () {
        return new PriceChannelOverlay();
    };
    PriceChannelOverlay.prototype.rg = function (a, b, c, d) {
        switch (b) {
            case "HighColumn":
            case "LowColumn":
                this.aba = false;
                break;
        }
        _super.prototype.rg.call(this, a, b, c, d);
        switch (b) {
            case PriceChannelOverlay.$$p[0]:
                this.aba = false;
                this.ry(false);
                break;
        }
    };
    PriceChannelOverlay.prototype.hf = function (a, b, c) {
        var d = _super.prototype.hf.call(this, a, b, c);
        if (this.ya == null || this.yb == null) {
            d = false;
        }
        return d;
    };
    PriceChannelOverlay.prototype.abb = function () {
        this.abh.clear();
        this.abg.clear();
        var a = truncate(MathUtil.d(this.abi, 0, this.dp.count));
        var b = Math.min(this.ya.count, this.yb.count);
        var c = this.y0(this.ya);
        var d = this.y0(this.yb);
        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.abh.add(g);
            this.abg.add(h);
        }
        return true;
    };
    PriceChannelOverlay.prototype.aam = function (a, b) {
        _super.prototype.aam.call(this, a, b);
        var c = b.ca;
        var d = b.b9;
        var e = this.getEffectiveViewport1(b);
        var f = new ScalerParams(0, c, d, this.xg.df, e);
        var g = new ScalerParams(0, c, d, this.xz.df, e);
        g.b = this.i0();
        var h = this.xg;
        var i = this.xz;
        a.h.clear();
        a.p.clear();
        a.s.clear();
        var j = 0;
        var k = typeCast(ISortingAxis_$type, this.xg);
        if (k != null && k.i$b.count != this.dp.count) {
            return;
        }
        j = this.y7(c, d, e);
        if (!this.aba) {
            this.aba = this.abb();
        }
        g.b = this.i0();
        var l = this.xg.fw(2, f) - this.xg.fw(1, f);
        for (var m = b.cd.c; m <= b.cd.d; ++m) {
            var n = void 0;
            if (k == null) {
                n = b.cd.getBucket(m);
            }
            else {
                var o = k.i$b._inner[m];
                var p = k.i$d(o);
                var q = this.abh._inner[m];
                var r = this.abg._inner[m];
                var s = q;
                var t = r;
                var u = p;
                while (m < b.cd.d) {
                    o = k.i$b._inner[m + 1];
                    u = k.i$d(o);
                    if (u - p > l) {
                        break;
                    }
                    m++;
                    s = Math.max(q, this.abh._inner[m]);
                    t = Math.min(r, this.abg._inner[m]);
                }
                if (!isInfinity(t) && !isInfinity(s)) {
                    var v = NaN;
                    if (!isNaN_(p)) {
                        v = this.xg.ft(p, f);
                    }
                    n = [v, t, s];
                }
                else {
                    n = [NaN, NaN, NaN];
                }
            }
            var w = Math.max(1, l);
            if (!isNaN_(n[0]) && m * w >= this.abc) {
                if (this.xg != null && typeCast(ISortingAxis_$type, this.xg) !== null) {
                    n[0] = n[0] + j;
                }
                else {
                    n[0] = h.ft(n[0], f) + j;
                }
                n[1] = i.ft(n[1], g);
                n[2] = i.ft(n[2], g);
                a.h.add(n);
            }
        }
    };
    PriceChannelOverlay.prototype.pb = function (a, b) {
        _super.prototype.pb.call(this, a, b);
        var c = b;
        if (c != null) {
            c.ck();
        }
    };
    PriceChannelOverlay.prototype.aao = function (a, b) {
        _super.prototype.aao.call(this, a, b);
        var c = typeCast(PriceChannelOverlayView.$, b);
        if (c == null) {
            return;
        }
        var d = this.getEffectiveViewport1(b);
        if (b.cg(a)) {
            c.ck();
            var e_1 = a.h.count;
            var f = function (g) { return a.h._inner[g][0]; };
            var g = function (h) { return a.h._inner[e_1 - 1 - h][0]; };
            var h = function (i) { return a.h._inner[i][1]; };
            var i = function (j) { return a.h._inner[e_1 - 1 - j][2]; };
            c.cl(e_1, f, g, h, i);
            b.ci(a);
        }
        this.xp.a2(this, this.yo(), runOn(this, this.w8), this.zd(b), this.zf(b));
        var j = false;
        var k = this.xp.b;
        var l = a.h;
        var m = this.dp.count;
        if (k != null) {
            j = true;
        }
        if (j) {
            var n = new ScalerParams(0, b.ca, b.b9, this.xg.df, d);
            this.aal(l, -1, m, this.xg, n, b.t, -1);
        }
        var o = c.cr;
        var p = c.cs;
        var q = c.cn;
        this.xp.ad(o, true, false, true, true);
        this.xp.ad(p, true, false, true, true);
        this.xp.ad(q, false, true, false, false);
        q._opacity = this.xp.j * this.ia;
    };
    PriceChannelOverlay.prototype.ct = function () {
        return new PriceChannelOverlayView(this);
    };
    PriceChannelOverlay.prototype.q7 = function (a) {
        _super.prototype.q7.call(this, a);
        this.abf = typeCast(PriceChannelOverlayView.$, a);
    };
    PriceChannelOverlay.prototype.i8 = function (a, b, c) {
        if (this.dc == null) {
            return NaN;
        }
        var d = this.getEffectiveViewport1(this.cw);
        var e = new ScalerParams(0, this.dc.xm, this.cw.b9, this.xg.df, d);
        var f = this.y7(this.dc.xm, this.cw.b9, d);
        return this.ja(new RangeValueList(this.abh, this.abg), a, this.xg, e, f, runOn(this, this.y6), b, c);
    };
    PriceChannelOverlay.prototype.kc = function (a, b) {
        if (this.abh == null || this.abg == null) {
            return _super.prototype.kc.call(this, a, b);
        }
        return this.kd(a, b, this.xg, runOn(this, this.y6), new RangeValueList(this.abh, this.abg));
    };
    PriceChannelOverlay.prototype.ke = function (a, b) {
        if (this.abh == null || this.abg == null) {
            return _super.prototype.ke.call(this, a, b);
        }
        return this.kf(a, b, this.xg, runOn(this, this.y6), new RangeValueList(this.abh, this.abg));
    };
    PriceChannelOverlay.prototype.i0 = function () {
        return Series.i2(this.abg, null);
    };
    PriceChannelOverlay.$t = markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:abi:abk', [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.cf.dp.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.cj.abh._inner[g]) && !isNaN_(this.f.cj.abg._inner[g])) {
                    d = Math.max(d, this.f.cj.abh._inner[g]);
                    e = Math.min(e, this.f.cj.abg._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.co = new Polygon();
        _this.ct = new Polyline();
        _this.cu = new Polyline();
        _this.cj = null;
        _this.cm = new Polygon();
        _this.cp = new Polyline();
        _this.cq = new Polyline();
        _this.cj = a;
        return _this;
    }
    Object.defineProperty(PriceChannelOverlayView.prototype, "cn", {
        get: function () {
            return this.co;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PriceChannelOverlayView.prototype, "cr", {
        get: function () {
            return this.ct;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PriceChannelOverlayView.prototype, "cs", {
        get: function () {
            return this.cu;
        },
        enumerable: false,
        configurable: true
    });
    PriceChannelOverlayView.prototype.a4 = function () {
        _super.prototype.a4.call(this);
        if (!this.t) {
        }
    };
    PriceChannelOverlayView.prototype.ce = function () {
        return new PriceChannelBucketCalculator(this);
    };
    PriceChannelOverlayView.prototype.ck = function () {
        this.co.an.clear();
        this.ct.an.clear();
        this.cu.an.clear();
        this.a2();
    };
    PriceChannelOverlayView.prototype.cl = 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.f.ie))), _d = _c.next(); !_d.done; _d = _c.next()) {
                var f = _d.value;
                this.co.an.add({ $type: Point_$type, x: b(f), y: d(f) });
                this.ct.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.f.ie))), _f = _e.next(); !_f.done; _f = _e.next()) {
                var g = _f.value;
                this.co.an.add({ $type: Point_$type, x: c(g), y: e(g) });
                this.cu.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.a2();
    };
    PriceChannelOverlayView.prototype.bq = function () {
        _super.prototype.bq.call(this);
        this.cm.an = this.co.an;
        this.cp.an = this.ct.an;
        this.cq.an = this.cu.an;
        var a = this.b3();
        this.cm._fill = a;
        this.cm._opacity = 1;
        this.cp._stroke = a;
        this.cp.ad = this.f.ig + 3;
        this.cq._stroke = a;
        this.cq.ad = this.f.ig + 3;
    };
    PriceChannelOverlayView.prototype.bj = function (a, b) {
        _super.prototype.bj.call(this, a, b);
        if (a.d) {
            if (b) {
                a.u(this.cm);
                a.v(this.cp);
                a.v(this.cq);
            }
            else {
                a.u(this.co);
                a.v(this.ct);
                a.v(this.cu);
            }
        }
    };
    PriceChannelOverlayView.prototype.ax = function (a) {
        _super.prototype.ax.call(this, a);
        this.f.bc.exportPolygonData(a, this.co, "fill", ["Fill"]);
        this.f.bc.exportPolylineData(a, this.ct, "bottom", ["Lower", "Main"]);
        this.f.bc.exportPolylineData(a, this.cu, "top", ["Upper"]);
    };
    PriceChannelOverlayView.$t = markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
    return PriceChannelOverlayView;
}(FinancialSeriesView));
export { PriceChannelOverlayView };
