/*
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 { HorizontalAnchoredCategorySeries } from "./HorizontalAnchoredCategorySeries";
import { Brush } from "igniteui-react-core/ES2015/Brush";
import { DependencyProperty } from "igniteui-react-core/ES2015/DependencyProperty";
import { Type, runOn, markType, fromEnum } from "igniteui-react-core/ES2015/type";
import { Rect } from "igniteui-react-core/ES2015/Rect";
import { Pool$1 } from "igniteui-react-core/ES2015/Pool$1";
import { ArrayExtension } from "igniteui-react-core/ES2015/ArrayExtension";
import { Rectangle } from "igniteui-react-core/ES2015/Rectangle";
import { List$1 } from "igniteui-react-core/ES2015/List$1";
import { ScalerParams } from "./ScalerParams";
import { PropertyMetadata } from "igniteui-react-core/ES2015/PropertyMetadata";
import { isNaN_ } from "igniteui-react-core/ES2015/number";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
export class WaterfallSeries extends HorizontalAnchoredCategorySeries {
    constructor() {
        super();
        this.ab = WaterfallSeries.$;
    }
    bf() {
        return new WaterfallSeriesView(this);
    }
    ii(a) {
        super.ii(a);
        this.p6 = a;
    }
    preferredCategoryMode(a) {
        return 2;
    }
    get_cy() {
        return true;
    }
    get cy() {
        return this.get_cy();
    }
    i6(a, b) {
        super.i6(a, b);
        this.qh = a;
        this.qi = b;
    }
    kx() {
        return this.qh;
    }
    get_nj() {
        return true;
    }
    get nj() {
        return this.get_nj();
    }
    io(a, b, c, d) {
        super.io(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;
        }
    }
    de(a, b) {
        if (this.dh(a, b)) {
            return true;
        }
        if (this.ls(a, b)) {
            return true;
        }
        return false;
    }
    li(a) {
        if (this.p6 == null || this.p6.c5 == null || this.p6.c5.count == 0 || this.xAxis == null) {
            return Rect.empty;
        }
        let b = this.p6.c5;
        let c = this.k4(a);
        let d = -1;
        let e = this.xAxis.b8;
        let f = this.lm.right * 2;
        if (e) {
            d = ArrayExtension.binarySearch$1(Rectangle.$, b, (g) => {
                let 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, (g) => {
                let 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;
        }
        let g = d;
        let h = d;
        if (g < 0) {
            g--;
        }
        if (h < b.count - 1) {
            h++;
        }
        let i = this.qj(g);
        let j = this.qj(d);
        let k = this.qj(h);
        let l = i.left + i.width / 2;
        let m = j.left + j.width / 2;
        let n = k.left + k.width / 2;
        let o = Math.abs(l - c.x);
        let p = Math.abs(m - c.x);
        let q = Math.abs(n - c.x);
        let r = i.containsPoint(c);
        let s = j.containsPoint(c);
        let 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;
    }
    qj(a) {
        return this.p6.db(a);
    }
    m4() {
        return 1;
    }
    hl(a, b) {
        super.hl(a, b);
        this.p6.c5.count = 0;
    }
    eb() {
        return this.pn.jj(this.bi.bq, this.bi.bp, this.getEffectiveViewport1(this.bi));
    }
    ob(a, b) {
        let c = b;
        super.ob(a, b);
        let d = b.bq;
        let e = b.bp;
        let f = this.getEffectiveViewport1(b);
        let g = this.pn.jj(d, e, f);
        let h = this.p7;
        let i = this.p8;
        let j;
        let k = this.ow(b);
        let l = NaN;
        let m = c.c5;
        let n;
        let 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;
        let p = false;
        let q = this.m2.c;
        if (q != null) {
            p = true;
        }
        let r = this.pn.cc;
        let s = this.valueColumn.count;
        let t = a.f;
        let u = this.pn;
        let v = new ScalerParams(0, d, e, this.pn.b8, f);
        let w = this.kr;
        let x = this.qh;
        let y = this.ks;
        let z = this.qi || y;
        if (a.f.count > 0) {
            j = a.f._inner[0][0] - 0.5 * g;
            let 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 (let ab = 1; ab < a.f.count; ++ab) {
            let ac = a.f._inner[ab];
            j = a.f._inner[ab][0] - 0.5 * g;
            let 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);
    }
    get useHighMarkerFidelity() {
        return this.nq;
    }
}
WaterfallSeries.$t = markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
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]]);
export class WaterfallSeriesView extends AnchoredCategorySeriesView {
    constructor(a) {
        super(a);
        this.c4 = null;
        this.c6 = null;
        this.dd = new Rectangle();
        this.c5 = null;
        this.c4 = a;
        this.c5 = ((() => {
            let $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;
        })());
    }
    ap() {
        super.ap();
        this.c6 = new List$1(Rectangle.$, 0);
        if (!this.n) {
            this.e.eo = 4;
            this.c4.qh = ((() => {
                let $ret = new Brush();
                $ret.fill = "#C62828";
                return $ret;
            })());
            this.c4.qi = ((() => {
                let $ret = new Brush();
                $ret.fill = "#C62828";
                return $ret;
            })());
            this.e.bj = 5;
        }
    }
    de() {
        let a = new Rectangle();
        this.c6.add(a);
        a._visibility = 1;
        return a;
    }
    c7(a) {
        a._visibility = 0;
    }
    c9(a) {
        a._visibility = 1;
    }
    c8(a) {
        this.c6.remove(a);
    }
    da(a, b, c) {
        let d = false;
        if (a.o != c) {
            d = true;
            a.o = c;
        }
        if (a.n != b) {
            d = true;
            a.n = b;
        }
        if (d) {
            this.an();
        }
    }
    z(a) {
        return this.c6._inner[a];
    }
    y(a) {
        let 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;
        let c = this.bl(a);
        this.dd._fill = c;
        this.dd._stroke = c;
        this.dd.ac = this.e.es + 3;
        return this.dd;
    }
    a3(a, b) {
        super.a3(a, b);
        if (a.d) {
            for (let c = 0; c < this.c6.count; c++) {
                let d = this.x(c, b);
                this.ba(d, c, b);
                a.v(d);
            }
        }
    }
    ai(a) {
        super.ai(a);
        let b = 0;
        let c = new List$1(Rectangle.$, 0);
        for (let d of fromEnum(this.c5.a)) {
            c.add(d);
        }
        c.aa((e, f) => {
            if (e.n < f.n) {
                return -1;
            }
            else if (e.n > f.n) {
                return 1;
            }
            else {
                return 0;
            }
        });
        for (let e of fromEnum(c)) {
            let f = "Negative";
            if (e._fill == this.e.kr) {
                f = "Positive";
            }
            this.e.a2.exportRectangleData(a, e, "column" + b, ["Main", f]);
        }
        b++;
    }
    db(a) {
        let b = this.c5.item(a);
        return new Rect(0, b.n, b.o, b.width, b.height);
    }
    dc(a) {
        return new Rect(0, a.n, a.o, a.width, a.height);
    }
}
WaterfallSeriesView.$t = markType(WaterfallSeriesView, 'WaterfallSeriesView', AnchoredCategorySeriesView.$);
/*<BeginStatics Name="Infragistics.Controls.Charts.WaterfallSeries" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.WaterfallSeries" />*/
