/*
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 { truncate, isNaN_ } from "igniteui-react-core";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
import { BrushUtil } from "igniteui-react-core";
/**
 * @hidden
 */
export let WaterfallSeries = /*@__PURE__*/ (() => {
    class WaterfallSeries extends HorizontalAnchoredCategorySeries {
        bi() {
            return new WaterfallSeries();
        }
        get_f4() {
            return true;
        }
        get_fj() {
            return true;
        }
        hr() {
            let a = super.hr();
            {
                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.rv));
                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.rv));
                a.add(c);
            }
            return a;
        }
        ji() {
            if (!isNaN_(this.jh)) {
                return super.ji();
            }
            return Defaults.h;
        }
        get_e8() {
            return true;
        }
        cq() {
            return new WaterfallSeriesView(this);
        }
        qx(a) {
            super.qx(a);
            this.acd = a;
        }
        constructor() {
            super();
            this.ab = WaterfallSeries.$;
        }
        preferredCategoryMode(a) {
            return 2;
        }
        get_fk() {
            return true;
        }
        rx(a, b) {
            super.rx(a, b);
            this.aco = a;
            this.acp = b;
        }
        vq() {
            return this.aco;
        }
        vr() {
            return this.acp;
        }
        cw() {
            if (this.cx == 0) {
                return 2;
            }
            return super.cw();
        }
        get_eb() {
            return true;
        }
        q5(a, b, c, d) {
            super.q5(a, b, c, d);
            switch (b) {
                case WaterfallSeries.$$p[3]:
                case WaterfallSeries.$$p[2]:
                case WaterfallSeries.$$p[0]:
                case WaterfallSeries.$$p[1]:
                    this.rn(false);
                    break;
            }
        }
        gu(a, b) {
            if (this.gx(a, b)) {
                return true;
            }
            if (this.w9(a, b)) {
                return true;
            }
            return false;
        }
        wh(a) {
            if (this.acd == null || this.acd.dg == null || this.acd.dg.count == 0 || this.xAxis == null) {
                return Rect.empty;
            }
            let b = this.acd.dg;
            let c = this.v1(a);
            let d = -1;
            let e = this.xAxis.ch;
            let f = this.wl.right * 2;
            if (e) {
                d = ArrayExtension.binarySearch$1(Rectangle.$, b, (g) => {
                    let h = this.acd.dn(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.acd.dn(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.acq(g);
            let j = this.acq(d);
            let k = this.acq(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;
        }
        acq(a) {
            return this.acd.dm(a);
        }
        yv() {
            return 1;
        }
        o3(a, b) {
            super.o3(a, b);
            this.acd.dg.count = 0;
        }
        get_aas() {
            return 1;
        }
        iu() {
            return this.abu.k5(this.ct.by, this.ct.bx, this.getEffectiveViewport1(this.ct));
        }
        z4(a, b) {
            let c = b;
            super.z4(a, b);
            let d = b.by;
            let e = b.bx;
            let f = this.getEffectiveViewport1(b);
            let g = this.abu.k5(d, e, f);
            let h = this.ace;
            let i = this.acf;
            let j;
            let k = this.aaq(b);
            let l = NaN;
            let m = c.dg;
            let n;
            let o = 0;
            this.yt.a2(this, this.zd(), runOn(this, this.ye), this.zm(b), this.zn(b));
            this.yt.r = this.ace;
            this.yt.s = this.acf;
            this.yt.k = this.ace;
            this.yt.l = this.acf;
            let p = false;
            let q = this.yt.b;
            if (q != null) {
                p = true;
            }
            let r = this.abu.cn;
            let s = this.valueColumn.count;
            let t = a.f;
            let u = this.abu;
            let v = new ScalerParams(0, d, e, this.abu.ch, f);
            let w = this.u3;
            let x = this.aco;
            let y = this.u7;
            let z = this.acp || 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.dl(n, j, k);
                        n.width = g;
                        n.height = Math.abs(k - aa);
                        this.yt.ak = x;
                        this.yt.ag = x;
                        this.yt.al = z;
                        this.yt.ah = z;
                        this.yt.f = true;
                        let ab = this.yt.aw(s, 0)[0];
                        if (r && a.m != null && 0 < a.m.count) {
                            ab = truncate(Math.round(a.m._inner[0]));
                        }
                        if (p) {
                            this.z0(t, 0, s, u, v, b.q, ab);
                        }
                        this.yt.ad(n, false, false, false, false);
                        n.ap = this.yt.k;
                        n.aq = this.yt.l;
                    }
                    else {
                        n = m.item(o);
                        o++;
                        c.dl(n, j, aa);
                        n.width = g;
                        n.height = Math.abs(aa - k);
                        this.yt.ak = w;
                        this.yt.ag = w;
                        this.yt.al = y;
                        this.yt.ah = y;
                        this.yt.f = false;
                        let ac = this.yt.aw(s, o)[0];
                        if (r && a.m != null && o >= 0 && o < a.m.count) {
                            ac = truncate(Math.round(a.m._inner[o]));
                        }
                        if (p) {
                            this.z0(t, 0, s, u, v, b.q, ac);
                        }
                        this.yt.ad(n, false, false, false, false);
                        n.ap = this.yt.k;
                        n.aq = this.yt.l;
                    }
                    l = aa;
                }
                else {
                    l = k;
                }
            }
            for (let ad = 1; ad < a.f.count; ++ad) {
                let ae = a.f._inner[ad];
                j = a.f._inner[ad][0] - 0.5 * g;
                let af = ae[1];
                if (!isNaN_(af)) {
                    n = m.item(o);
                    o++;
                    c.dl(n, j, Math.min(l, af));
                    n.width = g;
                    n.height = Math.abs(l - af);
                    this.yt.ak = w;
                    this.yt.ag = w;
                    this.yt.al = y;
                    this.yt.ah = y;
                    this.yt.f = false;
                    let ag = this.yt.aw(s, o)[0];
                    if (r && a.m != null && o >= 0 && o < a.m.count) {
                        ag = truncate(Math.round(a.m._inner[o]));
                    }
                    if (l > af) {
                        if (p) {
                            this.z0(t, ad, s, u, v, b.q, ag);
                        }
                    }
                    else {
                        this.yt.ak = x;
                        this.yt.ag = x;
                        this.yt.al = z;
                        this.yt.ah = z;
                        this.yt.f = true;
                        if (p) {
                            this.z0(t, ad, s, u, v, b.q, ag);
                        }
                    }
                    this.yt.ad(n, false, false, false, false);
                    n.ap = this.yt.k;
                    n.aq = this.yt.l;
                    l = af;
                }
            }
            m.count = o;
            b.c3(a);
        }
        get useHighMarkerFidelity() {
            return this.zh;
        }
    }
    WaterfallSeries.$t = /*@__PURE__*/ markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
    WaterfallSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, WaterfallSeries, 'raisePropertyChanged', ['NegativeBrush:aco:ack', [Brush.$, null], 'NegativeOutline:acp:acl', [Brush.$, null], 'RadiusX:ace:acm', [1, 0], 'RadiusY:acf:acn', [1, 0]]);
    return WaterfallSeries;
})();
/**
 * @hidden
 */
export let WaterfallSeriesView = /*@__PURE__*/ (() => {
    class WaterfallSeriesView extends AnchoredCategorySeriesView {
        au() {
            super.au();
            this.dh = new List$1(Rectangle.$, 0);
            if (!this.q) {
                this.df.w2 = Defaults.c;
                this.df.jn = Defaults.i;
                this.df.aco = Defaults.ah;
                this.df.acp = Defaults.ai;
            }
        }
        constructor(a) {
            super(a);
            this.df = null;
            this.dh = null;
            this.dp = new Rectangle();
            this.dg = null;
            this.df = a;
            this.dg = ((() => {
                let $ret = new Pool$1(Rectangle.$);
                $ret.create = runOn(this, this.dq);
                $ret.activate = runOn(this, this.di);
                $ret.disactivate = runOn(this, this.dk);
                $ret.destroy = runOn(this, this.dj);
                return $ret;
            })());
        }
        dq() {
            let a = new Rectangle();
            this.dh.add(a);
            a._visibility = 1;
            return a;
        }
        di(a) {
            a._visibility = 0;
        }
        dk(a) {
            a._visibility = 1;
        }
        dj(a) {
            this.dh.remove(a);
        }
        dl(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.dh._inner[a];
        }
        ab(a) {
            let b = this.dh._inner[a];
            this.dp._visibility = b._visibility;
            this.dp.n = b.n;
            this.dp.o = b.o;
            this.dp.width = b.width;
            this.dp.height = b.height;
            let c = this.bs(a);
            this.dp._fill = c;
            this.dp._stroke = c;
            this.dp.ad = this.e.ic + 3;
            return this.dp;
        }
        a8(a, b) {
            super.a8(a, b);
            if (a.d) {
                for (let c = 0; c < this.dh.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.dg.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 (BrushUtil.d(e._fill, this.e.u3)) {
                    f = "Positive";
                }
                this.e.bb.exportRectangleData(a, e, "column" + b, ["Main", f]);
            }
            b++;
        }
        dm(a) {
            let b = this.dg.item(a);
            return new Rect(0, b.n, b.o, b.width, b.height);
        }
        dn(a) {
            return new Rect(0, a.n, a.o, a.width, a.height);
        }
    }
    WaterfallSeriesView.$t = /*@__PURE__*/ markType(WaterfallSeriesView, 'WaterfallSeriesView', AnchoredCategorySeriesView.$);
    return WaterfallSeriesView;
})();
