/*
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";
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
 */
export let WaterfallSeries = /*@__PURE__*/ (() => {
    class WaterfallSeries extends HorizontalAnchoredCategorySeries {
        bc() {
            return new WaterfallSeries();
        }
        get_fk() {
            return true;
        }
        get_ez() {
            return true;
        }
        g1() {
            let a = super.g1();
            {
                let b = ((() => {
                    let $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.pz));
                a.add(b);
            }
            {
                let c = ((() => {
                    let $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.pz));
                a.add(c);
            }
            return a;
        }
        iq() {
            if (!isNaN_(this.ip)) {
                return super.iq();
            }
            return Defaults.h;
        }
        get_ep() {
            return true;
        }
        cd() {
            return new WaterfallSeriesView(this);
        }
        o2(a) {
            super.o2(a);
            this.zg = a;
        }
        constructor() {
            super();
            this.ab = WaterfallSeries.$;
        }
        preferredCategoryMode(a) {
            return 2;
        }
        get_e0() {
            return true;
        }
        p1(a, b) {
            super.p1(a, b);
            this.zr = a;
            this.zs = b;
        }
        s5() {
            return this.zr;
        }
        s6() {
            return this.zs;
        }
        cj() {
            if (this.ck == 0) {
                return 2;
            }
            return super.cj();
        }
        get_dv() {
            return true;
        }
        pa(a, b, c, d) {
            super.pa(a, b, c, d);
            switch (b) {
                case WaterfallSeries.$$p[3]:
                case WaterfallSeries.$$p[2]:
                case WaterfallSeries.$$p[0]:
                case WaterfallSeries.$$p[1]:
                    this.pr(false);
                    break;
            }
        }
        f5(a, b) {
            if (this.f8(a, b)) {
                return true;
            }
            if (this.uf(a, b)) {
                return true;
            }
            return false;
        }
        tu(a) {
            if (this.zg == null || this.zg.de == null || this.zg.de.count == 0 || this.xAxis == null) {
                return Rect.empty;
            }
            let b = this.zg.de;
            let c = this.te(a);
            let d = -1;
            let e = this.xAxis.ch;
            let f = this.ty.right * 2;
            if (e) {
                d = ArrayExtension.binarySearch$1(Rectangle.$, b, (g) => {
                    let h = this.zg.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, (g) => {
                    let h = this.zg.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;
            }
            let g = d;
            let h = d;
            if (g < 0) {
                g--;
            }
            if (h < b.count - 1) {
                h++;
            }
            let i = this.zt(g);
            let j = this.zt(d);
            let k = this.zt(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;
        }
        zt(a) {
            return this.zg.dk(a);
        }
        vy() {
            return 1;
        }
        nk(a, b) {
            super.nk(a, b);
            this.zg.de.count = 0;
        }
        get_xv() {
            return 1;
        }
        h1() {
            return this.yx.k4(this.cg.by, this.cg.bx, this.getEffectiveViewport1(this.cg));
        }
        w7(a, b) {
            let c = b;
            super.w7(a, b);
            let d = b.by;
            let e = b.bx;
            let f = this.getEffectiveViewport1(b);
            let g = this.yx.k4(d, e, f);
            let h = this.zh;
            let i = this.zi;
            let j;
            let k = this.xt(b);
            let l = NaN;
            let m = c.de;
            let n;
            let o = 0;
            this.vw.a2(this, this.wg(), runOn(this, this.vh), this.wp(b), this.wq(b));
            this.vw.r = this.zh;
            this.vw.s = this.zi;
            this.vw.k = this.zh;
            this.vw.l = this.zi;
            let p = false;
            let q = this.vw.b;
            if (q != null) {
                p = true;
            }
            let r = this.yx.cn;
            let s = this.valueColumn.count;
            let t = a.f;
            let u = this.yx;
            let v = new ScalerParams(0, d, e, this.yx.ch, f);
            let w = this.su;
            let x = this.zr;
            let y = this.sx;
            let z = this.zs || 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.dj(n, j, k);
                        n.width = g;
                        n.height = Math.abs(k - aa);
                        this.vw.ak = x;
                        this.vw.ag = x;
                        this.vw.al = z;
                        this.vw.ah = z;
                        this.vw.f = true;
                        if (p) {
                            this.w3(t, 0, s, u, v, b.q);
                        }
                        this.vw.ad(n, false, false, false, false);
                        n.ap = this.vw.k;
                        n.aq = this.vw.l;
                    }
                    else {
                        n = m.item(o);
                        o++;
                        c.dj(n, j, aa);
                        n.width = g;
                        n.height = Math.abs(aa - k);
                        this.vw.ak = w;
                        this.vw.ag = w;
                        this.vw.al = y;
                        this.vw.ah = y;
                        this.vw.f = false;
                        if (p) {
                            this.w3(t, 0, s, u, v, b.q);
                        }
                        this.vw.ad(n, false, false, false, false);
                        n.ap = this.vw.k;
                        n.aq = this.vw.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.dj(n, j, Math.min(l, ad));
                    n.width = g;
                    n.height = Math.abs(l - ad);
                    this.vw.ak = w;
                    this.vw.ag = w;
                    this.vw.al = y;
                    this.vw.ah = y;
                    this.vw.f = false;
                    if (l > ad) {
                        if (p) {
                            this.w3(t, ab, s, u, v, b.q);
                        }
                    }
                    else {
                        this.vw.ak = x;
                        this.vw.ag = x;
                        this.vw.al = z;
                        this.vw.ah = z;
                        this.vw.f = true;
                        if (p) {
                            this.w3(t, ab, s, u, v, b.q);
                        }
                    }
                    this.vw.ad(n, false, false, false, false);
                    n.ap = this.vw.k;
                    n.aq = this.vw.l;
                    l = ad;
                }
            }
            m.count = o;
            b.c1(a);
        }
        get useHighMarkerFidelity() {
            return this.wk;
        }
    }
    WaterfallSeries.$t = /*@__PURE__*/ markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
    WaterfallSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, WaterfallSeries, 'raisePropertyChanged', ['NegativeBrush:zr:zn', [Brush.$, null], 'NegativeOutline:zs:zo', [Brush.$, null], 'RadiusX:zh:zp', [1, 0], 'RadiusY:zi:zq', [1, 0]]);
    return WaterfallSeries;
})();
/**
 * @hidden
 */
export let WaterfallSeriesView = /*@__PURE__*/ (() => {
    class WaterfallSeriesView extends AnchoredCategorySeriesView {
        au() {
            super.au();
            this.df = new List$1(Rectangle.$, 0);
            if (!this.q) {
                this.dd.uc = Defaults.c;
                this.dd.iv = Defaults.i;
                this.dd.zr = Defaults.ah;
                this.dd.zs = Defaults.ai;
            }
        }
        constructor(a) {
            super(a);
            this.dd = null;
            this.df = null;
            this.dm = new Rectangle();
            this.de = null;
            this.dd = a;
            this.de = ((() => {
                let $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;
            })());
        }
        dn() {
            let a = new Rectangle();
            this.df.add(a);
            a._visibility = 1;
            return a;
        }
        dg(a) {
            a._visibility = 0;
        }
        di(a) {
            a._visibility = 1;
        }
        dh(a) {
            this.df.remove(a);
        }
        dj(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.as();
            }
        }
        ac(a) {
            return this.df._inner[a];
        }
        ab(a) {
            let 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;
            let c = this.bs(a);
            this.dm._fill = c;
            this.dm._stroke = c;
            this.dm.ad = this.e.hl + 3;
            return this.dm;
        }
        a8(a, b) {
            super.a8(a, b);
            if (a.d) {
                for (let c = 0; c < this.df.count; c++) {
                    let d = this.aa(c, b);
                    this.bf(d, c, b);
                    a.w(d);
                }
            }
        }
        an(a) {
            super.an(a);
            let b = 0;
            let c = new List$1(Rectangle.$, 0);
            for (let d of fromEnum(this.de.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.su) {
                    f = "Positive";
                }
                this.e.a5.exportRectangleData(a, e, "column" + b, ["Main", f]);
            }
            b++;
        }
        dk(a) {
            let b = this.de.item(a);
            return new Rect(0, b.n, b.o, b.width, b.height);
        }
        dl(a) {
            return new Rect(0, a.n, a.o, a.width, a.height);
        }
    }
    WaterfallSeriesView.$t = /*@__PURE__*/ markType(WaterfallSeriesView, 'WaterfallSeriesView', AnchoredCategorySeriesView.$);
    return WaterfallSeriesView;
})();
