/*
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 { Rectangle } from "igniteui-react-core/ES2015/Rectangle";
import { ArrayExtension } from "igniteui-react-core/ES2015/ArrayExtension";
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";
/**
 * @hidden
 */
export class WaterfallSeries extends HorizontalAnchoredCategorySeries {
    constructor() {
        super();
        this.ab = WaterfallSeries.$;
    }
    bf() {
        return new WaterfallSeriesView(this);
    }
    im(a) {
        super.im(a);
        this.qa = a;
    }
    preferredCategoryMode(a) {
        return 2;
    }
    get_cz() {
        return true;
    }
    jb(a, b) {
        super.jb(a, b);
        this.ql = a;
        this.qm = b;
    }
    k2() {
        return this.ql;
    }
    get_no() {
        return true;
    }
    is(a, b, c, d) {
        super.is(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;
        }
    }
    dg(a, b) {
        if (this.dj(a, b)) {
            return true;
        }
        if (this.lx(a, b)) {
            return true;
        }
        return false;
    }
    ln(a) {
        if (this.qa == null || this.qa.c7 == null || this.qa.c7.count == 0 || this.xAxis == null) {
            return Rect.empty;
        }
        let b = this.qa.c7;
        let c = this.k9(a);
        let d = -1;
        let e = this.xAxis.b8;
        let f = this.lr.right * 2;
        if (e) {
            d = ArrayExtension.binarySearch$1(Rectangle.$, b, (g) => {
                let 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, (g) => {
                let 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;
        }
        let g = d;
        let h = d;
        if (g < 0) {
            g--;
        }
        if (h < b.count - 1) {
            h++;
        }
        let i = this.qn(g);
        let j = this.qn(d);
        let k = this.qn(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;
    }
    qn(a) {
        return this.qa.dd(a);
    }
    m9() {
        return 1;
    }
    hp(a, b) {
        super.hp(a, b);
        this.qa.c7.count = 0;
    }
    ed() {
        return this.pr.jk(this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
    }
    oh(a, b) {
        let c = b;
        super.oh(a, b);
        let d = b.bs;
        let e = b.br;
        let f = this.getEffectiveViewport1(b);
        let g = this.pr.jk(d, e, f);
        let h = this.qb;
        let i = this.qc;
        let j;
        let k = this.o0(b);
        let l = NaN;
        let m = c.c7;
        let n;
        let 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;
        let p = false;
        let q = this.m7.c;
        if (q != null) {
            p = true;
        }
        let r = this.pr.cc;
        let s = this.valueColumn.count;
        let t = a.f;
        let u = this.pr;
        let v = new ScalerParams(0, d, e, this.pr.b8, f);
        let w = this.kw;
        let x = this.ql;
        let y = this.kx;
        let z = this.qm || 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.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 (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.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);
    }
    get useHighMarkerFidelity() {
        return this.nv;
    }
}
WaterfallSeries.$t = markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
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
 */
export class WaterfallSeriesView extends AnchoredCategorySeriesView {
    constructor(a) {
        super(a);
        this.c6 = null;
        this.c8 = null;
        this.df = new Rectangle();
        this.c7 = null;
        this.c6 = a;
        this.c7 = ((() => {
            let $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;
        })());
    }
    ap() {
        super.ap();
        this.c8 = new List$1(Rectangle.$, 0);
        if (!this.n) {
            this.e.er = 4;
            this.c6.ql = ((() => {
                let $ret = new Brush();
                $ret.fill = "#C62828";
                return $ret;
            })());
            this.c6.qm = ((() => {
                let $ret = new Brush();
                $ret.fill = "#C62828";
                return $ret;
            })());
            this.e.bj = 5;
        }
    }
    dg() {
        let a = new Rectangle();
        this.c8.add(a);
        a._visibility = 1;
        return a;
    }
    c9(a) {
        a._visibility = 0;
    }
    db(a) {
        a._visibility = 1;
    }
    da(a) {
        this.c8.remove(a);
    }
    dc(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.c8._inner[a];
    }
    y(a) {
        let 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;
        let c = this.bm(a);
        this.df._fill = c;
        this.df._stroke = c;
        this.df.ac = this.e.ev + 3;
        return this.df;
    }
    a3(a, b) {
        super.a3(a, b);
        if (a.d) {
            for (let c = 0; c < this.c8.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.c7.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.kw) {
                f = "Positive";
            }
            this.e.a2.exportRectangleData(a, e, "column" + b, ["Main", f]);
        }
        b++;
    }
    dd(a) {
        let b = this.c7.item(a);
        return new Rect(0, b.n, b.o, b.width, b.height);
    }
    de(a) {
        return new Rect(0, a.n, a.o, a.width, a.height);
    }
}
WaterfallSeriesView.$t = markType(WaterfallSeriesView, 'WaterfallSeriesView', AnchoredCategorySeriesView.$);
