/*
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 { HorizontalAnchoredCategorySeries } from "./HorizontalAnchoredCategorySeries";
import { Brush } from "igniteui-react-core/ES5/Brush";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { Type, runOn, markType, fromEnum } from "igniteui-react-core/ES5/type";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { Pool$1 } from "igniteui-react-core/ES5/Pool$1";
import { ArrayExtension } from "igniteui-react-core/ES5/ArrayExtension";
import { Rectangle } from "igniteui-react-core/ES5/Rectangle";
import { List$1 } from "igniteui-react-core/ES5/List$1";
import { ScalerParams } from "./ScalerParams";
import { PropertyMetadata } from "igniteui-react-core/ES5/PropertyMetadata";
import { isNaN_ } from "igniteui-react-core/ES5/number";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
var WaterfallSeries = /** @class */ (function (_super) {
    tslib_1.__extends(WaterfallSeries, _super);
    function WaterfallSeries() {
        var _this = _super.call(this) || this;
        _this.ab = WaterfallSeries.$;
        return _this;
    }
    WaterfallSeries.prototype.bf = function () {
        return new WaterfallSeriesView(this);
    };
    WaterfallSeries.prototype.ii = function (a) {
        _super.prototype.ii.call(this, a);
        this.p6 = a;
    };
    WaterfallSeries.prototype.preferredCategoryMode = function (a) {
        return 2;
    };
    WaterfallSeries.prototype.get_cy = function () {
        return true;
    };
    Object.defineProperty(WaterfallSeries.prototype, "cy", {
        get: function () {
            return this.get_cy();
        },
        enumerable: true,
        configurable: true
    });
    WaterfallSeries.prototype.i6 = function (a, b) {
        _super.prototype.i6.call(this, a, b);
        this.qh = a;
        this.qi = b;
    };
    WaterfallSeries.prototype.kx = function () {
        return this.qh;
    };
    WaterfallSeries.prototype.get_nj = function () {
        return true;
    };
    Object.defineProperty(WaterfallSeries.prototype, "nj", {
        get: function () {
            return this.get_nj();
        },
        enumerable: true,
        configurable: true
    });
    WaterfallSeries.prototype.io = function (a, b, c, d) {
        _super.prototype.io.call(this, a, b, c, d);
        switch (b) {
            case WaterfallSeries.$$p[3]:
            case WaterfallSeries.$$p[2]:
            case WaterfallSeries.$$p[0]:
            case WaterfallSeries.$$p[1]:
                this.i1(false);
                break;
        }
    };
    WaterfallSeries.prototype.de = function (a, b) {
        if (this.dh(a, b)) {
            return true;
        }
        if (this.ls(a, b)) {
            return true;
        }
        return false;
    };
    WaterfallSeries.prototype.li = function (a) {
        var _this = this;
        if (this.p6 == null || this.p6.c5 == null || this.p6.c5.count == 0 || this.xAxis == null) {
            return Rect.empty;
        }
        var b = this.p6.c5;
        var c = this.k4(a);
        var d = -1;
        var e = this.xAxis.b8;
        var f = this.lm.right * 2;
        if (e) {
            d = ArrayExtension.binarySearch$1(Rectangle.$, b, function (g) {
                var h = _this.p6.dc(g);
                return (f - c.x) < (f - (h.left + h.width / 2)) ? -1 : ((f - c.x) > (f - (h.left + h.width / 2)) ? 1 : 0);
            });
        }
        else {
            d = ArrayExtension.binarySearch$1(Rectangle.$, b, function (g) {
                var h = _this.p6.dc(g);
                return c.x < (h.left + h.width / 2) ? -1 : (c.x > (h.left + h.width / 2) ? 1 : 0);
            });
        }
        if (d < 0) {
            d = ~d;
            d--;
        }
        if (d < 0) {
            d = 0;
        }
        if (d > b.count - 1) {
            d = b.count - 1;
        }
        var g = d;
        var h = d;
        if (g < 0) {
            g--;
        }
        if (h < b.count - 1) {
            h++;
        }
        var i = this.qj(g);
        var j = this.qj(d);
        var k = this.qj(h);
        var l = i.left + i.width / 2;
        var m = j.left + j.width / 2;
        var n = k.left + k.width / 2;
        var o = Math.abs(l - c.x);
        var p = Math.abs(m - c.x);
        var q = Math.abs(n - c.x);
        var r = i.containsPoint(c);
        var s = j.containsPoint(c);
        var t = k.containsPoint(c);
        if (p <= o && p <= q) {
            if (!e && t) {
                return k;
            }
            if (e && r) {
                return i;
            }
            return j;
        }
        if (o <= p && o <= q) {
            if (!e && s) {
                return j;
            }
            return i;
        }
        if (q <= p && q <= o) {
            if (e && s) {
                return j;
            }
            return k;
        }
        return Rect.empty;
    };
    WaterfallSeries.prototype.qj = function (a) {
        return this.p6.db(a);
    };
    WaterfallSeries.prototype.m4 = function () {
        return 1;
    };
    WaterfallSeries.prototype.hl = function (a, b) {
        _super.prototype.hl.call(this, a, b);
        this.p6.c5.count = 0;
    };
    WaterfallSeries.prototype.eb = function () {
        return this.pn.jj(this.bi.bq, this.bi.bp, this.getEffectiveViewport1(this.bi));
    };
    WaterfallSeries.prototype.ob = function (a, b) {
        var c = b;
        _super.prototype.ob.call(this, a, b);
        var d = b.bq;
        var e = b.bp;
        var f = this.getEffectiveViewport1(b);
        var g = this.pn.jj(d, e, f);
        var h = this.p7;
        var i = this.p8;
        var j;
        var k = this.ow(b);
        var l = NaN;
        var m = c.c5;
        var n;
        var o = 0;
        this.m2.x(this, this.nn(), this.pn, runOn(this, this.mo), this.nv(b), this.nw(b));
        this.m2.p = this.p7;
        this.m2.q = this.p8;
        this.m2.j = this.p7;
        this.m2.k = this.p8;
        var p = false;
        var q = this.m2.c;
        if (q != null) {
            p = true;
        }
        var r = this.pn.cc;
        var s = this.valueColumn.count;
        var t = a.f;
        var u = this.pn;
        var v = new ScalerParams(0, d, e, this.pn.b8, f);
        var w = this.kr;
        var x = this.qh;
        var y = this.ks;
        var z = this.qi || y;
        if (a.f.count > 0) {
            j = a.f._inner[0][0] - 0.5 * g;
            var aa = a.f._inner[0][1];
            if (!isNaN_(aa)) {
                if (aa > k) {
                    n = m.item(o);
                    o++;
                    c.da(n, j, k);
                    n.width = g;
                    n.height = Math.abs(k - aa);
                    this.m2.al = x;
                    this.m2.ah = x;
                    this.m2.am = z;
                    this.m2.ai = z;
                    this.m2.f = true;
                    if (p) {
                        this.n7(t, 0, s, u, v, b.n);
                    }
                    this.m2.ae(n, false, false, false, false);
                    n.al = this.m2.j;
                    n.am = this.m2.k;
                }
                else {
                    n = m.item(o);
                    o++;
                    c.da(n, j, aa);
                    n.width = g;
                    n.height = Math.abs(aa - k);
                    this.m2.al = w;
                    this.m2.ah = w;
                    this.m2.am = y;
                    this.m2.ai = y;
                    this.m2.f = false;
                    if (p) {
                        this.n7(t, 0, s, u, v, b.n);
                    }
                    this.m2.ae(n, false, false, false, false);
                    n.al = this.m2.j;
                    n.am = this.m2.k;
                }
                l = aa;
            }
            else {
                l = k;
            }
        }
        for (var ab = 1; ab < a.f.count; ++ab) {
            var ac = a.f._inner[ab];
            j = a.f._inner[ab][0] - 0.5 * g;
            var ad = ac[1];
            if (!isNaN_(ad)) {
                n = m.item(o);
                o++;
                c.da(n, j, Math.min(l, ad));
                n.width = g;
                n.height = Math.abs(l - ad);
                this.m2.al = w;
                this.m2.ah = w;
                this.m2.am = y;
                this.m2.ai = y;
                this.m2.f = false;
                if (l > ad) {
                    if (p) {
                        this.n7(t, ab, s, u, v, b.n);
                    }
                }
                else {
                    this.m2.al = x;
                    this.m2.ah = x;
                    this.m2.am = z;
                    this.m2.ai = z;
                    this.m2.f = true;
                    if (p) {
                        this.n7(t, ab, s, u, v, b.n);
                    }
                }
                this.m2.ae(n, false, false, false, false);
                n.al = this.m2.j;
                n.am = this.m2.k;
                l = ad;
            }
        }
        m.count = o;
        b.cs(a);
    };
    Object.defineProperty(WaterfallSeries.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.nq;
        },
        enumerable: true,
        configurable: true
    });
    WaterfallSeries.$t = markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
    return WaterfallSeries;
}(HorizontalAnchoredCategorySeries));
export { WaterfallSeries };
Type.dep(DependencyProperty, PropertyMetadata, WaterfallSeries, 'raisePropertyChanged', ['NegativeBrush:qh:qd', [Brush.$, null], 'NegativeOutline:qi:qe', [Brush.$, null], 'RadiusX:p7:qf', [1, 2], 'RadiusY:p8:qg', [1, 2]]);
var WaterfallSeriesView = /** @class */ (function (_super) {
    tslib_1.__extends(WaterfallSeriesView, _super);
    function WaterfallSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.c4 = null;
        _this.c6 = null;
        _this.dd = new Rectangle();
        _this.c5 = null;
        _this.c4 = a;
        _this.c5 = ((function () {
            var $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(_this, _this.de);
            $ret.activate = runOn(_this, _this.c7);
            $ret.disactivate = runOn(_this, _this.c9);
            $ret.destroy = runOn(_this, _this.c8);
            return $ret;
        })());
        return _this;
    }
    WaterfallSeriesView.prototype.ap = function () {
        _super.prototype.ap.call(this);
        this.c6 = new List$1(Rectangle.$, 0);
        if (!this.n) {
            this.e.eo = 4;
            this.c4.qh = ((function () {
                var $ret = new Brush();
                $ret.fill = "#C62828";
                return $ret;
            })());
            this.c4.qi = ((function () {
                var $ret = new Brush();
                $ret.fill = "#C62828";
                return $ret;
            })());
            this.e.bj = 5;
        }
    };
    WaterfallSeriesView.prototype.de = function () {
        var a = new Rectangle();
        this.c6.add(a);
        a._visibility = 1;
        return a;
    };
    WaterfallSeriesView.prototype.c7 = function (a) {
        a._visibility = 0;
    };
    WaterfallSeriesView.prototype.c9 = function (a) {
        a._visibility = 1;
    };
    WaterfallSeriesView.prototype.c8 = function (a) {
        this.c6.remove(a);
    };
    WaterfallSeriesView.prototype.da = function (a, b, c) {
        var d = false;
        if (a.o != c) {
            d = true;
            a.o = c;
        }
        if (a.n != b) {
            d = true;
            a.n = b;
        }
        if (d) {
            this.an();
        }
    };
    WaterfallSeriesView.prototype.z = function (a) {
        return this.c6._inner[a];
    };
    WaterfallSeriesView.prototype.y = function (a) {
        var b = this.c6._inner[a];
        this.dd._visibility = b._visibility;
        this.dd.n = b.n;
        this.dd.o = b.o;
        this.dd.width = b.width;
        this.dd.height = b.height;
        var c = this.bl(a);
        this.dd._fill = c;
        this.dd._stroke = c;
        this.dd.ac = this.e.es + 3;
        return this.dd;
    };
    WaterfallSeriesView.prototype.a3 = function (a, b) {
        _super.prototype.a3.call(this, a, b);
        if (a.d) {
            for (var c = 0; c < this.c6.count; c++) {
                var d = this.x(c, b);
                this.ba(d, c, b);
                a.v(d);
            }
        }
    };
    WaterfallSeriesView.prototype.ai = function (a) {
        _super.prototype.ai.call(this, a);
        var b = 0;
        var c = new List$1(Rectangle.$, 0);
        try {
            for (var _a = tslib_1.__values(fromEnum(this.c5.a)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var d = _b.value;
                c.add(d);
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_1) throw e_1.error; }
        }
        c.aa(function (e, f) {
            if (e.n < f.n) {
                return -1;
            }
            else if (e.n > f.n) {
                return 1;
            }
            else {
                return 0;
            }
        });
        try {
            for (var _d = tslib_1.__values(fromEnum(c)), _e = _d.next(); !_e.done; _e = _d.next()) {
                var e = _e.value;
                var f = "Negative";
                if (e._fill == this.e.kr) {
                    f = "Positive";
                }
                this.e.a2.exportRectangleData(a, e, "column" + b, ["Main", f]);
            }
        }
        catch (e_2_1) { e_2 = { error: e_2_1 }; }
        finally {
            try {
                if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
            }
            finally { if (e_2) throw e_2.error; }
        }
        b++;
        var e_1, _c, e_2, _f;
    };
    WaterfallSeriesView.prototype.db = function (a) {
        var b = this.c5.item(a);
        return new Rect(0, b.n, b.o, b.width, b.height);
    };
    WaterfallSeriesView.prototype.dc = function (a) {
        return new Rect(0, a.n, a.o, a.width, a.height);
    };
    WaterfallSeriesView.$t = markType(WaterfallSeriesView, 'WaterfallSeriesView', AnchoredCategorySeriesView.$);
    return WaterfallSeriesView;
}(AnchoredCategorySeriesView));
export { WaterfallSeriesView };
/*<BeginStatics Name="Infragistics.Controls.Charts.WaterfallSeries" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.WaterfallSeries" />*/
