/*
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-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { Defaults } from "./Defaults";
import { runOn, markType, markDep, fromEnum } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { Rectangle } from "igniteui-angular-core";
import { ArrayExtension } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_ } from "igniteui-angular-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_ek = function () {
        return true;
    };
    WaterfallSeries.prototype.get_d2 = function () {
        return true;
    };
    WaterfallSeries.prototype.gu = function () {
        if (!isNaN_(this.gt)) {
            return _super.prototype.gu.call(this);
        }
        return Defaults.h;
    };
    WaterfallSeries.prototype.get_dt = function () {
        return true;
    };
    WaterfallSeries.prototype.bx = function () {
        return new WaterfallSeriesView(this);
    };
    WaterfallSeries.prototype.ly = function (a) {
        _super.prototype.ly.call(this, a);
        this.u6 = a;
    };
    WaterfallSeries.prototype.preferredCategoryMode = function (a) {
        return 2;
    };
    WaterfallSeries.prototype.get_d3 = function () {
        return true;
    };
    WaterfallSeries.prototype.mm = function (a, b) {
        _super.prototype.mm.call(this, a, b);
        this.vh = a;
        this.vi = b;
    };
    WaterfallSeries.prototype.o8 = function () {
        return this.vh;
    };
    WaterfallSeries.prototype.o9 = function () {
        return this.vi;
    };
    WaterfallSeries.prototype.b3 = function () {
        if (this.b4 == 0) {
            return 2;
        }
        return _super.prototype.b3.call(this);
    };
    WaterfallSeries.prototype.get_c2 = function () {
        return true;
    };
    WaterfallSeries.prototype.l3 = function (a, b, c, d) {
        _super.prototype.l3.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.mh(false);
                break;
        }
    };
    WaterfallSeries.prototype.ev = function (a, b) {
        if (this.ey(a, b)) {
            return true;
        }
        if (this.qf(a, b)) {
            return true;
        }
        return false;
    };
    WaterfallSeries.prototype.pu = function (a) {
        var _this = this;
        if (this.u6 == null || this.u6.db == null || this.u6.db.count == 0 || this.xAxis == null) {
            return Rect.empty;
        }
        var b = this.u6.db;
        var c = this.pg(a);
        var d = -1;
        var e = this.xAxis.cg;
        var f = this.py.right * 2;
        if (e) {
            d = ArrayExtension.binarySearch$1(Rectangle.$, b, function (g) {
                var h = _this.u6.di(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.u6.di(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.vj(g);
        var j = this.vj(d);
        var k = this.vj(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.vj = function (a) {
        return this.u6.dh(a);
    };
    WaterfallSeries.prototype.ry = function () {
        return 1;
    };
    WaterfallSeries.prototype.kx = function (a, b) {
        _super.prototype.kx.call(this, a, b);
        this.u6.db.count = 0;
    };
    WaterfallSeries.prototype.get_tr = function () {
        return 1;
    };
    WaterfallSeries.prototype.ga = function () {
        return this.un.k3(this.b0.bv, this.b0.bu, this.getEffectiveViewport1(this.b0));
    };
    WaterfallSeries.prototype.s6 = function (a, b) {
        var c = b;
        _super.prototype.s6.call(this, a, b);
        var d = b.bv;
        var e = b.bu;
        var f = this.getEffectiveViewport1(b);
        var g = this.un.k3(d, e, f);
        var h = this.u7;
        var i = this.u8;
        var j;
        var k = this.tp(b);
        var l = NaN;
        var m = c.db;
        var n;
        var o = 0;
        this.rw.a0(this, this.sg(), runOn(this, this.rh), this.so(b), this.sp(b));
        this.rw.r = this.u7;
        this.rw.s = this.u8;
        this.rw.k = this.u7;
        this.rw.l = this.u8;
        var p = false;
        var q = this.rw.b;
        if (q != null) {
            p = true;
        }
        var r = this.un.cm;
        var s = this.valueColumn.count;
        var t = a.f;
        var u = this.un;
        var v = new ScalerParams(0, d, e, this.un.cg, f);
        var w = this.oy;
        var x = this.vh;
        var y = this.o1;
        var z = this.vi || 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.dg(n, j, k);
                    n.width = g;
                    n.height = Math.abs(k - aa);
                    this.rw.ak = x;
                    this.rw.ag = x;
                    this.rw.al = z;
                    this.rw.ah = z;
                    this.rw.f = true;
                    if (p) {
                        this.s2(t, 0, s, u, v, b.q);
                    }
                    this.rw.ad(n, false, false, false, false);
                    n.am = this.rw.k;
                    n.an = this.rw.l;
                }
                else {
                    n = m.item(o);
                    o++;
                    c.dg(n, j, aa);
                    n.width = g;
                    n.height = Math.abs(aa - k);
                    this.rw.ak = w;
                    this.rw.ag = w;
                    this.rw.al = y;
                    this.rw.ah = y;
                    this.rw.f = false;
                    if (p) {
                        this.s2(t, 0, s, u, v, b.q);
                    }
                    this.rw.ad(n, false, false, false, false);
                    n.am = this.rw.k;
                    n.an = this.rw.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.dg(n, j, Math.min(l, ad));
                n.width = g;
                n.height = Math.abs(l - ad);
                this.rw.ak = w;
                this.rw.ag = w;
                this.rw.al = y;
                this.rw.ah = y;
                this.rw.f = false;
                if (l > ad) {
                    if (p) {
                        this.s2(t, ab, s, u, v, b.q);
                    }
                }
                else {
                    this.rw.ak = x;
                    this.rw.ag = x;
                    this.rw.al = z;
                    this.rw.ah = z;
                    this.rw.f = true;
                    if (p) {
                        this.s2(t, ab, s, u, v, b.q);
                    }
                }
                this.rw.ad(n, false, false, false, false);
                n.am = this.rw.k;
                n.an = this.rw.l;
                l = ad;
            }
        }
        m.count = o;
        b.cy(a);
    };
    Object.defineProperty(WaterfallSeries.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.sj;
        },
        enumerable: false,
        configurable: true
    });
    WaterfallSeries.$t = markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
    WaterfallSeries.$$p = markDep(DependencyProperty, PropertyMetadata, WaterfallSeries, 'raisePropertyChanged', ['NegativeBrush:vh:vd', [Brush.$, null], 'NegativeOutline:vi:ve', [Brush.$, null], 'RadiusX:u7:vf', [1, 0], 'RadiusY:u8:vg', [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.da = null;
        _this.dc = null;
        _this.dj = new Rectangle();
        _this.db = null;
        _this.da = a;
        _this.db = ((function () {
            var $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(_this, _this.dk);
            $ret.activate = runOn(_this, _this.dd);
            $ret.disactivate = runOn(_this, _this.df);
            $ret.destroy = runOn(_this, _this.de);
            return $ret;
        })());
        return _this;
    }
    WaterfallSeriesView.prototype.as = function () {
        _super.prototype.as.call(this);
        this.dc = new List$1(Rectangle.$, 0);
        if (!this.q) {
            this.da.qc = Defaults.c;
            this.da.gz = Defaults.i;
            this.da.vh = Defaults.ah;
            this.da.vi = Defaults.ai;
        }
    };
    WaterfallSeriesView.prototype.dk = function () {
        var a = new Rectangle();
        this.dc.add(a);
        a._visibility = 1;
        return a;
    };
    WaterfallSeriesView.prototype.dd = function (a) {
        a._visibility = 0;
    };
    WaterfallSeriesView.prototype.df = function (a) {
        a._visibility = 1;
    };
    WaterfallSeriesView.prototype.de = function (a) {
        this.dc.remove(a);
    };
    WaterfallSeriesView.prototype.dg = 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.aq();
        }
    };
    WaterfallSeriesView.prototype.ac = function (a) {
        return this.dc._inner[a];
    };
    WaterfallSeriesView.prototype.ab = function (a) {
        var b = this.dc._inner[a];
        this.dj._visibility = b._visibility;
        this.dj.n = b.n;
        this.dj.o = b.o;
        this.dj.width = b.width;
        this.dj.height = b.height;
        var c = this.bp(a);
        this.dj._fill = c;
        this.dj._stroke = c;
        this.dj.ac = this.e.fu + 3;
        return this.dj;
    };
    WaterfallSeriesView.prototype.a6 = function (a, b) {
        _super.prototype.a6.call(this, a, b);
        if (a.d) {
            for (var c = 0; c < this.dc.count; c++) {
                var d = this.aa(c, b);
                this.bd(d, c, b);
                a.v(d);
            }
        }
    };
    WaterfallSeriesView.prototype.al = function (a) {
        var e_1, _a, e_2, _b;
        _super.prototype.al.call(this, a);
        var b = 0;
        var c = new List$1(Rectangle.$, 0);
        try {
            for (var _c = __values(fromEnum(this.db.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.oy) {
                    f = "Positive";
                }
                this.e.a8.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.dh = function (a) {
        var b = this.db.item(a);
        return new Rect(0, b.n, b.o, b.width, b.height);
    };
    WaterfallSeriesView.prototype.di = 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 };
