/*
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 { Rectangle } from "igniteui-react-core/ES5/Rectangle";
import { ArrayExtension } from "igniteui-react-core/ES5/ArrayExtension";
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";
/**
 * @hidden
 */
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.im = function (a) {
        _super.prototype.im.call(this, a);
        this.qa = a;
    };
    WaterfallSeries.prototype.preferredCategoryMode = function (a) {
        return 2;
    };
    WaterfallSeries.prototype.get_cz = function () {
        return true;
    };
    WaterfallSeries.prototype.jb = function (a, b) {
        _super.prototype.jb.call(this, a, b);
        this.ql = a;
        this.qm = b;
    };
    WaterfallSeries.prototype.k2 = function () {
        return this.ql;
    };
    WaterfallSeries.prototype.get_no = function () {
        return true;
    };
    WaterfallSeries.prototype.is = function (a, b, c, d) {
        _super.prototype.is.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.i6(false);
                break;
        }
    };
    WaterfallSeries.prototype.dg = function (a, b) {
        if (this.dj(a, b)) {
            return true;
        }
        if (this.lx(a, b)) {
            return true;
        }
        return false;
    };
    WaterfallSeries.prototype.ln = function (a) {
        var _this = this;
        if (this.qa == null || this.qa.c7 == null || this.qa.c7.count == 0 || this.xAxis == null) {
            return Rect.empty;
        }
        var b = this.qa.c7;
        var c = this.k9(a);
        var d = -1;
        var e = this.xAxis.b8;
        var f = this.lr.right * 2;
        if (e) {
            d = ArrayExtension.binarySearch$1(Rectangle.$, b, function (g) {
                var h = _this.qa.de(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.qa.de(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.qn(g);
        var j = this.qn(d);
        var k = this.qn(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.qn = function (a) {
        return this.qa.dd(a);
    };
    WaterfallSeries.prototype.m9 = function () {
        return 1;
    };
    WaterfallSeries.prototype.hp = function (a, b) {
        _super.prototype.hp.call(this, a, b);
        this.qa.c7.count = 0;
    };
    WaterfallSeries.prototype.ed = function () {
        return this.pr.jk(this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
    };
    WaterfallSeries.prototype.oh = function (a, b) {
        var c = b;
        _super.prototype.oh.call(this, a, b);
        var d = b.bs;
        var e = b.br;
        var f = this.getEffectiveViewport1(b);
        var g = this.pr.jk(d, e, f);
        var h = this.qb;
        var i = this.qc;
        var j;
        var k = this.o0(b);
        var l = NaN;
        var m = c.c7;
        var n;
        var o = 0;
        this.m7.x(this, this.ns(), this.pr, runOn(this, this.mt), this.n0(b), this.n1(b));
        this.m7.p = this.qb;
        this.m7.q = this.qc;
        this.m7.j = this.qb;
        this.m7.k = this.qc;
        var p = false;
        var q = this.m7.c;
        if (q != null) {
            p = true;
        }
        var r = this.pr.cc;
        var s = this.valueColumn.count;
        var t = a.f;
        var u = this.pr;
        var v = new ScalerParams(0, d, e, this.pr.b8, f);
        var w = this.kw;
        var x = this.ql;
        var y = this.kx;
        var z = this.qm || 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.dc(n, j, k);
                    n.width = g;
                    n.height = Math.abs(k - aa);
                    this.m7.al = x;
                    this.m7.ah = x;
                    this.m7.am = z;
                    this.m7.ai = z;
                    this.m7.f = true;
                    if (p) {
                        this.od(t, 0, s, u, v, b.n);
                    }
                    this.m7.ae(n, false, false, false, false);
                    n.al = this.m7.j;
                    n.am = this.m7.k;
                }
                else {
                    n = m.item(o);
                    o++;
                    c.dc(n, j, aa);
                    n.width = g;
                    n.height = Math.abs(aa - k);
                    this.m7.al = w;
                    this.m7.ah = w;
                    this.m7.am = y;
                    this.m7.ai = y;
                    this.m7.f = false;
                    if (p) {
                        this.od(t, 0, s, u, v, b.n);
                    }
                    this.m7.ae(n, false, false, false, false);
                    n.al = this.m7.j;
                    n.am = this.m7.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.dc(n, j, Math.min(l, ad));
                n.width = g;
                n.height = Math.abs(l - ad);
                this.m7.al = w;
                this.m7.ah = w;
                this.m7.am = y;
                this.m7.ai = y;
                this.m7.f = false;
                if (l > ad) {
                    if (p) {
                        this.od(t, ab, s, u, v, b.n);
                    }
                }
                else {
                    this.m7.al = x;
                    this.m7.ah = x;
                    this.m7.am = z;
                    this.m7.ai = z;
                    this.m7.f = true;
                    if (p) {
                        this.od(t, ab, s, u, v, b.n);
                    }
                }
                this.m7.ae(n, false, false, false, false);
                n.al = this.m7.j;
                n.am = this.m7.k;
                l = ad;
            }
        }
        m.count = o;
        b.cu(a);
    };
    Object.defineProperty(WaterfallSeries.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.nv;
        },
        enumerable: true,
        configurable: true
    });
    WaterfallSeries.$t = markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
    return WaterfallSeries;
}(HorizontalAnchoredCategorySeries));
export { WaterfallSeries };
Type.dep(DependencyProperty, PropertyMetadata, WaterfallSeries, 'raisePropertyChanged', ['NegativeBrush:ql:qh', [Brush.$, null], 'NegativeOutline:qm:qi', [Brush.$, null], 'RadiusX:qb:qj', [1, 2], 'RadiusY:qc:qk', [1, 2]]);
/**
 * @hidden
 */
var WaterfallSeriesView = /** @class */ (function (_super) {
    tslib_1.__extends(WaterfallSeriesView, _super);
    function WaterfallSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.c6 = null;
        _this.c8 = null;
        _this.df = new Rectangle();
        _this.c7 = null;
        _this.c6 = a;
        _this.c7 = ((function () {
            var $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(_this, _this.dg);
            $ret.activate = runOn(_this, _this.c9);
            $ret.disactivate = runOn(_this, _this.db);
            $ret.destroy = runOn(_this, _this.da);
            return $ret;
        })());
        return _this;
    }
    WaterfallSeriesView.prototype.ap = function () {
        _super.prototype.ap.call(this);
        this.c8 = new List$1(Rectangle.$, 0);
        if (!this.n) {
            this.e.er = 4;
            this.c6.ql = ((function () {
                var $ret = new Brush();
                $ret.fill = "#C62828";
                return $ret;
            })());
            this.c6.qm = ((function () {
                var $ret = new Brush();
                $ret.fill = "#C62828";
                return $ret;
            })());
            this.e.bj = 5;
        }
    };
    WaterfallSeriesView.prototype.dg = function () {
        var a = new Rectangle();
        this.c8.add(a);
        a._visibility = 1;
        return a;
    };
    WaterfallSeriesView.prototype.c9 = function (a) {
        a._visibility = 0;
    };
    WaterfallSeriesView.prototype.db = function (a) {
        a._visibility = 1;
    };
    WaterfallSeriesView.prototype.da = function (a) {
        this.c8.remove(a);
    };
    WaterfallSeriesView.prototype.dc = 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.c8._inner[a];
    };
    WaterfallSeriesView.prototype.y = function (a) {
        var b = this.c8._inner[a];
        this.df._visibility = b._visibility;
        this.df.n = b.n;
        this.df.o = b.o;
        this.df.width = b.width;
        this.df.height = b.height;
        var c = this.bm(a);
        this.df._fill = c;
        this.df._stroke = c;
        this.df.ac = this.e.ev + 3;
        return this.df;
    };
    WaterfallSeriesView.prototype.a3 = function (a, b) {
        _super.prototype.a3.call(this, a, b);
        if (a.d) {
            for (var c = 0; c < this.c8.count; c++) {
                var d = this.x(c, b);
                this.ba(d, c, b);
                a.v(d);
            }
        }
    };
    WaterfallSeriesView.prototype.ai = function (a) {
        var e_1, _a, e_2, _b;
        _super.prototype.ai.call(this, a);
        var b = 0;
        var c = new List$1(Rectangle.$, 0);
        try {
            for (var _c = tslib_1.__values(fromEnum(this.c7.a)), _d = _c.next(); !_d.done; _d = _c.next()) {
                var d = _d.value;
                c.add(d);
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
            }
            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 _e = tslib_1.__values(fromEnum(c)), _f = _e.next(); !_f.done; _f = _e.next()) {
                var e = _f.value;
                var f = "Negative";
                if (e._fill == this.e.kw) {
                    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 (_f && !_f.done && (_b = _e.return)) _b.call(_e);
            }
            finally { if (e_2) throw e_2.error; }
        }
        b++;
    };
    WaterfallSeriesView.prototype.dd = function (a) {
        var b = this.c7.item(a);
        return new Rect(0, b.n, b.o, b.width, b.height);
    };
    WaterfallSeriesView.prototype.de = 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 };
