/*
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 {
        get_fj() {
            return true;
        }
        get_ey() {
            return true;
        }
        g0() {
            let a = super.g0();
            {
                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.px));
                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.px));
                a.add(c);
            }
            return a;
        }
        ip() {
            if (!isNaN_(this.io)) {
                return super.ip();
            }
            return Defaults.h;
        }
        get_eo() {
            return true;
        }
        cg() {
            return new WaterfallSeriesView(this);
        }
        o0(a) {
            super.o0(a);
            this.ze = a;
        }
        constructor() {
            super();
            this.ab = WaterfallSeries.$;
        }
        preferredCategoryMode(a) {
            return 2;
        }
        get_ez() {
            return true;
        }
        pz(a, b) {
            super.pz(a, b);
            this.zp = a;
            this.zq = b;
        }
        s3() {
            return this.zp;
        }
        s4() {
            return this.zq;
        }
        cm() {
            if (this.cn == 0) {
                return 2;
            }
            return super.cm();
        }
        get_du() {
            return true;
        }
        o8(a, b, c, d) {
            super.o8(a, b, c, d);
            switch (b) {
                case WaterfallSeries.$$p[3]:
                case WaterfallSeries.$$p[2]:
                case WaterfallSeries.$$p[0]:
                case WaterfallSeries.$$p[1]:
                    this.pp(false);
                    break;
            }
        }
        f4(a, b) {
            if (this.f7(a, b)) {
                return true;
            }
            if (this.ud(a, b)) {
                return true;
            }
            return false;
        }
        ts(a) {
            if (this.ze == null || this.ze.de == null || this.ze.de.count == 0 || this.xAxis == null) {
                return Rect.empty;
            }
            let b = this.ze.de;
            let c = this.tc(a);
            let d = -1;
            let e = this.xAxis.ch;
            let f = this.tw.right * 2;
            if (e) {
                d = ArrayExtension.binarySearch$1(Rectangle.$, b, (g) => {
                    let h = this.ze.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.ze.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.zr(g);
            let j = this.zr(d);
            let k = this.zr(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;
        }
        zr(a) {
            return this.ze.dk(a);
        }
        vw() {
            return 1;
        }
        nj(a, b) {
            super.nj(a, b);
            this.ze.de.count = 0;
        }
        get_xt() {
            return 1;
        }
        h0() {
            return this.yv.k4(this.cj.by, this.cj.bx, this.getEffectiveViewport1(this.cj));
        }
        w5(a, b) {
            let c = b;
            super.w5(a, b);
            let d = b.by;
            let e = b.bx;
            let f = this.getEffectiveViewport1(b);
            let g = this.yv.k4(d, e, f);
            let h = this.zf;
            let i = this.zg;
            let j;
            let k = this.xr(b);
            let l = NaN;
            let m = c.de;
            let n;
            let o = 0;
            this.vu.a2(this, this.we(), runOn(this, this.vf), this.wn(b), this.wo(b));
            this.vu.r = this.zf;
            this.vu.s = this.zg;
            this.vu.k = this.zf;
            this.vu.l = this.zg;
            let p = false;
            let q = this.vu.b;
            if (q != null) {
                p = true;
            }
            let r = this.yv.cn;
            let s = this.valueColumn.count;
            let t = a.f;
            let u = this.yv;
            let v = new ScalerParams(0, d, e, this.yv.ch, f);
            let w = this.ss;
            let x = this.zp;
            let y = this.sv;
            let z = this.zq || 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.vu.ak = x;
                        this.vu.ag = x;
                        this.vu.al = z;
                        this.vu.ah = z;
                        this.vu.f = true;
                        if (p) {
                            this.w1(t, 0, s, u, v, b.q);
                        }
                        this.vu.ad(n, false, false, false, false);
                        n.ap = this.vu.k;
                        n.aq = this.vu.l;
                    }
                    else {
                        n = m.item(o);
                        o++;
                        c.dj(n, j, aa);
                        n.width = g;
                        n.height = Math.abs(aa - k);
                        this.vu.ak = w;
                        this.vu.ag = w;
                        this.vu.al = y;
                        this.vu.ah = y;
                        this.vu.f = false;
                        if (p) {
                            this.w1(t, 0, s, u, v, b.q);
                        }
                        this.vu.ad(n, false, false, false, false);
                        n.ap = this.vu.k;
                        n.aq = this.vu.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.vu.ak = w;
                    this.vu.ag = w;
                    this.vu.al = y;
                    this.vu.ah = y;
                    this.vu.f = false;
                    if (l > ad) {
                        if (p) {
                            this.w1(t, ab, s, u, v, b.q);
                        }
                    }
                    else {
                        this.vu.ak = x;
                        this.vu.ag = x;
                        this.vu.al = z;
                        this.vu.ah = z;
                        this.vu.f = true;
                        if (p) {
                            this.w1(t, ab, s, u, v, b.q);
                        }
                    }
                    this.vu.ad(n, false, false, false, false);
                    n.ap = this.vu.k;
                    n.aq = this.vu.l;
                    l = ad;
                }
            }
            m.count = o;
            b.c1(a);
        }
        get useHighMarkerFidelity() {
            return this.wi;
        }
    }
    WaterfallSeries.$t = /*@__PURE__*/ markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
    WaterfallSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, WaterfallSeries, 'raisePropertyChanged', ['NegativeBrush:zp:zl', [Brush.$, null], 'NegativeOutline:zq:zm', [Brush.$, null], 'RadiusX:zf:zn', [1, 0], 'RadiusY:zg:zo', [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.ua = Defaults.c;
                this.dd.iu = Defaults.i;
                this.dd.zp = Defaults.ah;
                this.dd.zq = 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.hk + 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.ss) {
                    f = "Positive";
                }
                this.e.a9.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;
})();
