/*
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-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
 */
export let WaterfallSeries = /*@__PURE__*/ (() => {
    class WaterfallSeries extends HorizontalAnchoredCategorySeries {
        constructor() {
            super();
            this.ab = WaterfallSeries.$;
        }
        get_el() {
            return true;
        }
        get_d3() {
            return true;
        }
        gw() {
            if (!isNaN_(this.gv)) {
                return super.gw();
            }
            return Defaults.h;
        }
        get_du() {
            return true;
        }
        bx() {
            return new WaterfallSeriesView(this);
        }
        l2(a) {
            super.l2(a);
            this.vb = a;
        }
        preferredCategoryMode(a) {
            return 2;
        }
        get_d4() {
            return true;
        }
        mq(a, b) {
            super.mq(a, b);
            this.vm = a;
            this.vn = b;
        }
        pd() {
            return this.vm;
        }
        pe() {
            return this.vn;
        }
        b3() {
            if (this.b4 == 0) {
                return 2;
            }
            return super.b3();
        }
        get_c2() {
            return true;
        }
        l7(a, b, c, d) {
            super.l7(a, b, c, d);
            switch (b) {
                case WaterfallSeries.$$p[3]:
                case WaterfallSeries.$$p[2]:
                case WaterfallSeries.$$p[0]:
                case WaterfallSeries.$$p[1]:
                    this.ml(false);
                    break;
            }
        }
        ex(a, b) {
            if (this.e0(a, b)) {
                return true;
            }
            if (this.qk(a, b)) {
                return true;
            }
            return false;
        }
        pz(a) {
            if (this.vb == null || this.vb.db == null || this.vb.db.count == 0 || this.xAxis == null) {
                return Rect.empty;
            }
            let b = this.vb.db;
            let c = this.pl(a);
            let d = -1;
            let e = this.xAxis.cg;
            let f = this.p3.right * 2;
            if (e) {
                d = ArrayExtension.binarySearch$1(Rectangle.$, b, (g) => {
                    let h = this.vb.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, (g) => {
                    let h = this.vb.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;
            }
            let g = d;
            let h = d;
            if (g < 0) {
                g--;
            }
            if (h < b.count - 1) {
                h++;
            }
            let i = this.vo(g);
            let j = this.vo(d);
            let k = this.vo(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;
        }
        vo(a) {
            return this.vb.dh(a);
        }
        r3() {
            return 1;
        }
        k0(a, b) {
            super.k0(a, b);
            this.vb.db.count = 0;
        }
        get_tw() {
            return 1;
        }
        gc() {
            return this.us.k3(this.b0.bv, this.b0.bu, this.getEffectiveViewport1(this.b0));
        }
        tb(a, b) {
            let c = b;
            super.tb(a, b);
            let d = b.bv;
            let e = b.bu;
            let f = this.getEffectiveViewport1(b);
            let g = this.us.k3(d, e, f);
            let h = this.vc;
            let i = this.vd;
            let j;
            let k = this.tu(b);
            let l = NaN;
            let m = c.db;
            let n;
            let o = 0;
            this.r1.a0(this, this.sl(), runOn(this, this.rm), this.st(b), this.su(b));
            this.r1.r = this.vc;
            this.r1.s = this.vd;
            this.r1.k = this.vc;
            this.r1.l = this.vd;
            let p = false;
            let q = this.r1.b;
            if (q != null) {
                p = true;
            }
            let r = this.us.cm;
            let s = this.valueColumn.count;
            let t = a.f;
            let u = this.us;
            let v = new ScalerParams(0, d, e, this.us.cg, f);
            let w = this.o3;
            let x = this.vm;
            let y = this.o6;
            let z = this.vn || 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.dg(n, j, k);
                        n.width = g;
                        n.height = Math.abs(k - aa);
                        this.r1.ak = x;
                        this.r1.ag = x;
                        this.r1.al = z;
                        this.r1.ah = z;
                        this.r1.f = true;
                        if (p) {
                            this.s7(t, 0, s, u, v, b.q);
                        }
                        this.r1.ad(n, false, false, false, false);
                        n.am = this.r1.k;
                        n.an = this.r1.l;
                    }
                    else {
                        n = m.item(o);
                        o++;
                        c.dg(n, j, aa);
                        n.width = g;
                        n.height = Math.abs(aa - k);
                        this.r1.ak = w;
                        this.r1.ag = w;
                        this.r1.al = y;
                        this.r1.ah = y;
                        this.r1.f = false;
                        if (p) {
                            this.s7(t, 0, s, u, v, b.q);
                        }
                        this.r1.ad(n, false, false, false, false);
                        n.am = this.r1.k;
                        n.an = this.r1.l;
                    }
                    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.dg(n, j, Math.min(l, ad));
                    n.width = g;
                    n.height = Math.abs(l - ad);
                    this.r1.ak = w;
                    this.r1.ag = w;
                    this.r1.al = y;
                    this.r1.ah = y;
                    this.r1.f = false;
                    if (l > ad) {
                        if (p) {
                            this.s7(t, ab, s, u, v, b.q);
                        }
                    }
                    else {
                        this.r1.ak = x;
                        this.r1.ag = x;
                        this.r1.al = z;
                        this.r1.ah = z;
                        this.r1.f = true;
                        if (p) {
                            this.s7(t, ab, s, u, v, b.q);
                        }
                    }
                    this.r1.ad(n, false, false, false, false);
                    n.am = this.r1.k;
                    n.an = this.r1.l;
                    l = ad;
                }
            }
            m.count = o;
            b.cy(a);
        }
        get useHighMarkerFidelity() {
            return this.so;
        }
    }
    WaterfallSeries.$t = markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
    WaterfallSeries.$$p = markDep(DependencyProperty, PropertyMetadata, WaterfallSeries, 'raisePropertyChanged', ['NegativeBrush:vm:vi', [Brush.$, null], 'NegativeOutline:vn:vj', [Brush.$, null], 'RadiusX:vc:vk', [1, 0], 'RadiusY:vd:vl', [1, 0]]);
    return WaterfallSeries;
})();
/**
 * @hidden
 */
export let WaterfallSeriesView = /*@__PURE__*/ (() => {
    class WaterfallSeriesView extends AnchoredCategorySeriesView {
        constructor(a) {
            super(a);
            this.da = null;
            this.dc = null;
            this.dj = new Rectangle();
            this.db = null;
            this.da = a;
            this.db = ((() => {
                let $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;
            })());
        }
        as() {
            super.as();
            this.dc = new List$1(Rectangle.$, 0);
            if (!this.q) {
                this.da.qh = Defaults.c;
                this.da.g1 = Defaults.i;
                this.da.vm = Defaults.ah;
                this.da.vn = Defaults.ai;
            }
        }
        dk() {
            let a = new Rectangle();
            this.dc.add(a);
            a._visibility = 1;
            return a;
        }
        dd(a) {
            a._visibility = 0;
        }
        df(a) {
            a._visibility = 1;
        }
        de(a) {
            this.dc.remove(a);
        }
        dg(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.aq();
            }
        }
        ac(a) {
            return this.dc._inner[a];
        }
        ab(a) {
            let 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;
            let c = this.bp(a);
            this.dj._fill = c;
            this.dj._stroke = c;
            this.dj.ac = this.e.fw + 3;
            return this.dj;
        }
        a6(a, b) {
            super.a6(a, b);
            if (a.d) {
                for (let c = 0; c < this.dc.count; c++) {
                    let d = this.aa(c, b);
                    this.bd(d, c, b);
                    a.w(d);
                }
            }
        }
        al(a) {
            super.al(a);
            let b = 0;
            let c = new List$1(Rectangle.$, 0);
            for (let d of fromEnum(this.db.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.o3) {
                    f = "Positive";
                }
                this.e.a8.exportRectangleData(a, e, "column" + b, ["Main", f]);
            }
            b++;
        }
        dh(a) {
            let b = this.db.item(a);
            return new Rect(0, b.n, b.o, b.width, b.height);
        }
        di(a) {
            return new Rect(0, a.n, a.o, a.width, a.height);
        }
    }
    WaterfallSeriesView.$t = markType(WaterfallSeriesView, 'WaterfallSeriesView', AnchoredCategorySeriesView.$);
    return WaterfallSeriesView;
})();
