/*
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-react-core";
import { Series } from "./Series";
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 { 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) {
    __extends(PriceChannelOverlay, _super);
    function PriceChannelOverlay() {
        var _this = _super.call(this) || this;
        _this.aaz = new List$1(Number_$type, 0);
        _this.aay = new List$1(Number_$type, 0);
        _this.ab = PriceChannelOverlay.$;
        _this.w2 = new CategoryFrame(3);
        _this.w4 = new CategoryFrame(3);
        _this.w0 = new CategoryFrame(3);
        return _this;
    }
    PriceChannelOverlay.prototype.bi = function () {
        return new PriceChannelOverlay();
    };
    PriceChannelOverlay.prototype.q5 = function (a, b, c, d) {
        switch (b) {
            case "HighColumn":
            case "LowColumn":
                this.aas = false;
                break;
        }
        _super.prototype.q5.call(this, a, b, c, d);
        switch (b) {
            case PriceChannelOverlay.$$p[0]:
                this.aas = false;
                this.rn(false);
                break;
        }
    };
    PriceChannelOverlay.prototype.hc = function (a, b, c) {
        var d = _super.prototype.hc.call(this, a, b, c);
        if (this.xs == null || this.xt == null) {
            d = false;
        }
        return d;
    };
    PriceChannelOverlay.prototype.aat = function () {
        this.aaz.clear();
        this.aay.clear();
        var a = truncate(MathUtil.d(this.aa0, 0, this.dl.count));
        var b = Math.min(this.xs.count, this.xt.count);
        var c = this.yi(this.xs);
        var d = this.yi(this.xt);
        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.aaz.add(g);
            this.aay.add(h);
        }
        return true;
    };
    PriceChannelOverlay.prototype.z4 = function (a, b) {
        _super.prototype.z4.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.wy.ch, e);
        var g = new ScalerParams(0, c, d, this.xh.ch, e);
        g.b = this.iw();
        var h = this.wy;
        var i = this.xh;
        a.f.clear();
        a.n.clear();
        a.q.clear();
        var j = 0;
        var k = typeCast(ISortingAxis_$type, this.wy);
        if (k != null && k.i$b.count != this.dl.count) {
            return;
        }
        j = this.yp(c, d, e);
        if (!this.aas) {
            this.aas = this.aat();
        }
        g.b = this.iw();
        var l = this.wy.en(2, f) - this.wy.en(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.aaz._inner[m];
                var r = this.aay._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.aaz._inner[m]);
                    t = Math.min(r, this.aay._inner[m]);
                }
                if (!isInfinity(t) && !isInfinity(s)) {
                    var v = NaN;
                    if (!isNaN_(p)) {
                        v = this.wy.ek(p, f);
                    }
                    n = [v, t, s];
                }
                else {
                    n = [NaN, NaN, NaN];
                }
            }
            var w = Math.max(1, l);
            if (!isNaN_(n[0]) && m * w >= this.aau) {
                if (this.wy != null && typeCast(ISortingAxis_$type, this.wy) !== null) {
                    n[0] = n[0] + j;
                }
                else {
                    n[0] = h.ek(n[0], f) + j;
                }
                n[1] = i.ek(n[1], g);
                n[2] = i.ek(n[2], g);
                a.f.add(n);
            }
        }
    };
    PriceChannelOverlay.prototype.o3 = function (a, b) {
        _super.prototype.o3.call(this, a, b);
        var c = b;
        if (c != null) {
            c.b7();
        }
    };
    PriceChannelOverlay.prototype.z6 = function (a, b) {
        _super.prototype.z6.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.w7.a2(this, this.x6(), runOn(this, this.wq), this.yv(b), this.yx(b));
        var j = false;
        var k = this.w7.b;
        var l = a.f;
        var m = this.dl.count;
        if (k != null) {
            j = true;
        }
        if (j) {
            var n = new ScalerParams(0, b.by, b.bx, this.wy.ch, d);
            this.z3(l, -1, m, this.wy, n, b.q, -1);
        }
        var o = c.ce;
        var p = c.cf;
        var q = c.ca;
        this.w7.ad(o, true, false, true, true);
        this.w7.ad(p, true, false, true, true);
        this.w7.ad(q, false, true, false, false);
        q._opacity = this.w7.j * this.h7;
    };
    PriceChannelOverlay.prototype.cq = function () {
        return new PriceChannelOverlayView(this);
    };
    PriceChannelOverlay.prototype.qx = function (a) {
        _super.prototype.qx.call(this, a);
        this.aax = typeCast(PriceChannelOverlayView.$, a);
    };
    PriceChannelOverlay.prototype.i3 = function (a, b, c) {
        if (this.c9 == null) {
            return NaN;
        }
        var d = this.getEffectiveViewport1(this.ct);
        var e = new ScalerParams(0, this.c9.vl, this.ct.bx, this.wy.ch, d);
        var f = this.yp(this.c9.vl, this.ct.bx, d);
        return this.i5(new RangeValueList(this.aaz, this.aay), a, this.wy, e, f, runOn(this, this.yo), b, c);
    };
    PriceChannelOverlay.prototype.j6 = function (a, b) {
        if (this.aaz == null || this.aay == null) {
            return _super.prototype.j6.call(this, a, b);
        }
        return this.j7(a, b, this.wy, runOn(this, this.yo), new RangeValueList(this.aaz, this.aay));
    };
    PriceChannelOverlay.prototype.j8 = function (a, b) {
        if (this.aaz == null || this.aay == null) {
            return _super.prototype.j8.call(this, a, b);
        }
        return this.j9(a, b, this.wy, runOn(this, this.yo), new RangeValueList(this.aaz, this.aay));
    };
    PriceChannelOverlay.prototype.iw = function () {
        return Series.iy(this.aay, null);
    };
    PriceChannelOverlay.$t = markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:aa0:aa2', [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.dl.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.aaz._inner[g]) && !isNaN_(this.f.b6.aay._inner[g])) {
                    d = Math.max(d, this.f.b6.aaz._inner[g]);
                    e = Math.min(e, this.f.b6.aay._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.ib))), _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.ib))), _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.ic + 3;
        this.cd._stroke = a;
        this.cd.ad = this.e.ic + 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.bb.exportPolygonData(a, this.cb, "fill", ["Fill"]);
        this.e.bb.exportPolylineData(a, this.cg, "bottom", ["Lower", "Main"]);
        this.e.bb.exportPolylineData(a, this.ch, "top", ["Upper"]);
    };
    PriceChannelOverlayView.$t = markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
    return PriceChannelOverlayView;
}(FinancialSeriesView));
export { PriceChannelOverlayView };
