/*
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 { HorizontalAnchoredCategorySeries } from "./HorizontalAnchoredCategorySeries";
import { Brush } from "igniteui-react-core";
import { DependencyProperty } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { SeriesLayerPropertyOverlay } from "./SeriesLayerPropertyOverlay";
import { runOn, delegateCombine, markType, markDep, fromEnum } from "igniteui-react-core";
import { Defaults } from "./Defaults";
import { Rect } from "igniteui-react-core";
import { Pool$1 } from "igniteui-react-core";
import { Rectangle } from "igniteui-react-core";
import { ArrayExtension } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { PropertyMetadata } from "igniteui-react-core";
import { isNaN_ } from "igniteui-react-core";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
/**
 * @hidden
 */
var WaterfallSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(WaterfallSeries, _super);
    function WaterfallSeries() {
        var _this = _super.call(this) || this;
        _this.ab = WaterfallSeries.$;
        return _this;
    }
    WaterfallSeries.prototype.get_fj = function () {
        return true;
    };
    WaterfallSeries.prototype.get_ey = function () {
        return true;
    };
    WaterfallSeries.prototype.g0 = function () {
        var a = _super.prototype.g0.call(this);
        {
            var b = ((function () {
                var $ret = new SeriesLayerPropertyOverlay();
                $ret.r = true;
                $ret.ad = "NegativeBrush";
                $ret.p = true;
                $ret.q = true;
                return $ret;
            })());
            b.valueResolving = delegateCombine(b.valueResolving, runOn(this, this.px));
            a.add(b);
        }
        {
            var c = ((function () {
                var $ret = new SeriesLayerPropertyOverlay();
                $ret.r = true;
                $ret.ad = "NegativeOutline";
                $ret.p = true;
                $ret.q = true;
                return $ret;
            })());
            c.valueResolving = delegateCombine(c.valueResolving, runOn(this, this.px));
            a.add(c);
        }
        return a;
    };
    WaterfallSeries.prototype.ip = function () {
        if (!isNaN_(this.io)) {
            return _super.prototype.ip.call(this);
        }
        return Defaults.h;
    };
    WaterfallSeries.prototype.get_eo = function () {
        return true;
    };
    WaterfallSeries.prototype.cg = function () {
        return new WaterfallSeriesView(this);
    };
    WaterfallSeries.prototype.o0 = function (a) {
        _super.prototype.o0.call(this, a);
        this.ze = a;
    };
    WaterfallSeries.prototype.preferredCategoryMode = function (a) {
        return 2;
    };
    WaterfallSeries.prototype.get_ez = function () {
        return true;
    };
    WaterfallSeries.prototype.pz = function (a, b) {
        _super.prototype.pz.call(this, a, b);
        this.zp = a;
        this.zq = b;
    };
    WaterfallSeries.prototype.s3 = function () {
        return this.zp;
    };
    WaterfallSeries.prototype.s4 = function () {
        return this.zq;
    };
    WaterfallSeries.prototype.cm = function () {
        if (this.cn == 0) {
            return 2;
        }
        return _super.prototype.cm.call(this);
    };
    WaterfallSeries.prototype.get_du = function () {
        return true;
    };
    WaterfallSeries.prototype.o8 = function (a, b, c, d) {
        _super.prototype.o8.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.pp(false);
                break;
        }
    };
    WaterfallSeries.prototype.f4 = function (a, b) {
        if (this.f7(a, b)) {
            return true;
        }
        if (this.ud(a, b)) {
            return true;
        }
        return false;
    };
    WaterfallSeries.prototype.ts = function (a) {
        var _this = this;
        if (this.ze == null || this.ze.de == null || this.ze.de.count == 0 || this.xAxis == null) {
            return Rect.empty;
        }
        var b = this.ze.de;
        var c = this.tc(a);
        var d = -1;
        var e = this.xAxis.ch;
        var f = this.tw.right * 2;
        if (e) {
            d = ArrayExtension.binarySearch$1(Rectangle.$, b, function (g) {
                var h = _this.ze.dl(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.ze.dl(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.zr(g);
        var j = this.zr(d);
        var k = this.zr(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.zr = function (a) {
        return this.ze.dk(a);
    };
    WaterfallSeries.prototype.vw = function () {
        return 1;
    };
    WaterfallSeries.prototype.nj = function (a, b) {
        _super.prototype.nj.call(this, a, b);
        this.ze.de.count = 0;
    };
    WaterfallSeries.prototype.get_xt = function () {
        return 1;
    };
    WaterfallSeries.prototype.h0 = function () {
        return this.yv.k4(this.cj.by, this.cj.bx, this.getEffectiveViewport1(this.cj));
    };
    WaterfallSeries.prototype.w5 = function (a, b) {
        var c = b;
        _super.prototype.w5.call(this, a, b);
        var d = b.by;
        var e = b.bx;
        var f = this.getEffectiveViewport1(b);
        var g = this.yv.k4(d, e, f);
        var h = this.zf;
        var i = this.zg;
        var j;
        var k = this.xr(b);
        var l = NaN;
        var m = c.de;
        var n;
        var o = 0;
        this.vu.a2(this, this.we(), runOn(this, this.vf), this.wn(b), this.wo(b));
        this.vu.r = this.zf;
        this.vu.s = this.zg;
        this.vu.k = this.zf;
        this.vu.l = this.zg;
        var p = false;
        var q = this.vu.b;
        if (q != null) {
            p = true;
        }
        var r = this.yv.cn;
        var s = this.valueColumn.count;
        var t = a.f;
        var u = this.yv;
        var v = new ScalerParams(0, d, e, this.yv.ch, f);
        var w = this.ss;
        var x = this.zp;
        var y = this.sv;
        var z = this.zq || 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.dj(n, j, k);
                    n.width = g;
                    n.height = Math.abs(k - aa);
                    this.vu.ak = x;
                    this.vu.ag = x;
                    this.vu.al = z;
                    this.vu.ah = z;
                    this.vu.f = true;
                    if (p) {
                        this.w1(t, 0, s, u, v, b.q);
                    }
                    this.vu.ad(n, false, false, false, false);
                    n.ap = this.vu.k;
                    n.aq = this.vu.l;
                }
                else {
                    n = m.item(o);
                    o++;
                    c.dj(n, j, aa);
                    n.width = g;
                    n.height = Math.abs(aa - k);
                    this.vu.ak = w;
                    this.vu.ag = w;
                    this.vu.al = y;
                    this.vu.ah = y;
                    this.vu.f = false;
                    if (p) {
                        this.w1(t, 0, s, u, v, b.q);
                    }
                    this.vu.ad(n, false, false, false, false);
                    n.ap = this.vu.k;
                    n.aq = this.vu.l;
                }
                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.dj(n, j, Math.min(l, ad));
                n.width = g;
                n.height = Math.abs(l - ad);
                this.vu.ak = w;
                this.vu.ag = w;
                this.vu.al = y;
                this.vu.ah = y;
                this.vu.f = false;
                if (l > ad) {
                    if (p) {
                        this.w1(t, ab, s, u, v, b.q);
                    }
                }
                else {
                    this.vu.ak = x;
                    this.vu.ag = x;
                    this.vu.al = z;
                    this.vu.ah = z;
                    this.vu.f = true;
                    if (p) {
                        this.w1(t, ab, s, u, v, b.q);
                    }
                }
                this.vu.ad(n, false, false, false, false);
                n.ap = this.vu.k;
                n.aq = this.vu.l;
                l = ad;
            }
        }
        m.count = o;
        b.c1(a);
    };
    Object.defineProperty(WaterfallSeries.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.wi;
        },
        enumerable: false,
        configurable: true
    });
    WaterfallSeries.$t = markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
    WaterfallSeries.$$p = markDep(DependencyProperty, PropertyMetadata, WaterfallSeries, 'raisePropertyChanged', ['NegativeBrush:zp:zl', [Brush.$, null], 'NegativeOutline:zq:zm', [Brush.$, null], 'RadiusX:zf:zn', [1, 0], 'RadiusY:zg:zo', [1, 0]]);
    return WaterfallSeries;
}(HorizontalAnchoredCategorySeries));
export { WaterfallSeries };
/**
 * @hidden
 */
var WaterfallSeriesView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(WaterfallSeriesView, _super);
    function WaterfallSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.dd = null;
        _this.df = null;
        _this.dm = new Rectangle();
        _this.de = null;
        _this.dd = a;
        _this.de = ((function () {
            var $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(_this, _this.dn);
            $ret.activate = runOn(_this, _this.dg);
            $ret.disactivate = runOn(_this, _this.di);
            $ret.destroy = runOn(_this, _this.dh);
            return $ret;
        })());
        return _this;
    }
    WaterfallSeriesView.prototype.au = function () {
        _super.prototype.au.call(this);
        this.df = new List$1(Rectangle.$, 0);
        if (!this.q) {
            this.dd.ua = Defaults.c;
            this.dd.iu = Defaults.i;
            this.dd.zp = Defaults.ah;
            this.dd.zq = Defaults.ai;
        }
    };
    WaterfallSeriesView.prototype.dn = function () {
        var a = new Rectangle();
        this.df.add(a);
        a._visibility = 1;
        return a;
    };
    WaterfallSeriesView.prototype.dg = function (a) {
        a._visibility = 0;
    };
    WaterfallSeriesView.prototype.di = function (a) {
        a._visibility = 1;
    };
    WaterfallSeriesView.prototype.dh = function (a) {
        this.df.remove(a);
    };
    WaterfallSeriesView.prototype.dj = 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.as();
        }
    };
    WaterfallSeriesView.prototype.ac = function (a) {
        return this.df._inner[a];
    };
    WaterfallSeriesView.prototype.ab = function (a) {
        var b = this.df._inner[a];
        this.dm._visibility = b._visibility;
        this.dm.n = b.n;
        this.dm.o = b.o;
        this.dm.width = b.width;
        this.dm.height = b.height;
        var c = this.bs(a);
        this.dm._fill = c;
        this.dm._stroke = c;
        this.dm.ad = this.e.hk + 3;
        return this.dm;
    };
    WaterfallSeriesView.prototype.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        if (a.d) {
            for (var c = 0; c < this.df.count; c++) {
                var d = this.aa(c, b);
                this.bf(d, c, b);
                a.w(d);
            }
        }
    };
    WaterfallSeriesView.prototype.an = function (a) {
        var e_1, _a, e_2, _b;
        _super.prototype.an.call(this, a);
        var b = 0;
        var c = new List$1(Rectangle.$, 0);
        try {
            for (var _c = __values(fromEnum(this.de.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 = __values(fromEnum(c)), _f = _e.next(); !_f.done; _f = _e.next()) {
                var e = _f.value;
                var f = "Negative";
                if (e._fill == this.e.ss) {
                    f = "Positive";
                }
                this.e.a9.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.dk = function (a) {
        var b = this.de.item(a);
        return new Rect(0, b.n, b.o, b.width, b.height);
    };
    WaterfallSeriesView.prototype.dl = 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 };
