/*
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.ru));
                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.ru));
                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);
        }
        qw(a) {
            super.qw(a);
            this.acc = a;
        }
        constructor() {
            super();
            this.ab = WaterfallSeries.$;
        }
        preferredCategoryMode(a) {
            return 2;
        }
        get_fk() {
            return true;
        }
        rw(a, b) {
            super.rw(a, b);
            this.acn = a;
            this.aco = b;
        }
        vp() {
            return this.acn;
        }
        vq() {
            return this.aco;
        }
        cw() {
            if (this.cx == 0) {
                return 2;
            }
            return super.cw();
        }
        get_eb() {
            return true;
        }
        q4(a, b, c, d) {
            super.q4(a, b, c, d);
            switch (b) {
                case WaterfallSeries.$$p[3]:
                case WaterfallSeries.$$p[2]:
                case WaterfallSeries.$$p[0]:
                case WaterfallSeries.$$p[1]:
                    this.rm(false);
                    break;
            }
        }
        gu(a, b) {
            if (this.gx(a, b)) {
                return true;
            }
            if (this.w8(a, b)) {
                return true;
            }
            return false;
        }
        wg(a) {
            if (this.acc == null || this.acc.dg == null || this.acc.dg.count == 0 || this.xAxis == null) {
                return Rect.empty;
            }
            let b = this.acc.dg;
            let c = this.v0(a);
            let d = -1;
            let e = this.xAxis.ch;
            let f = this.wk.right * 2;
            if (e) {
                d = ArrayExtension.binarySearch$1(Rectangle.$, b, (g) => {
                    let h = this.acc.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.acc.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.acp(g);
            let j = this.acp(d);
            let k = this.acp(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;
        }
        acp(a) {
            return this.acc.dm(a);
        }
        yu() {
            return 1;
        }
        o2(a, b) {
            super.o2(a, b);
            this.acc.dg.count = 0;
        }
        get_aar() {
            return 1;
        }
        iu() {
            return this.abt.k5(this.ct.by, this.ct.bx, this.getEffectiveViewport1(this.ct));
        }
        z3(a, b) {
            let c = b;
            super.z3(a, b);
            let d = b.by;
            let e = b.bx;
            let f = this.getEffectiveViewport1(b);
            let g = this.abt.k5(d, e, f);
            let h = this.acd;
            let i = this.ace;
            let j;
            let k = this.aap(b);
            let l = NaN;
            let m = c.dg;
            let n;
            let o = 0;
            this.ys.a2(this, this.zc(), runOn(this, this.yd), this.zl(b), this.zm(b));
            this.ys.r = this.acd;
            this.ys.s = this.ace;
            this.ys.k = this.acd;
            this.ys.l = this.ace;
            let p = false;
            let q = this.ys.b;
            if (q != null) {
                p = true;
            }
            let r = this.abt.cn;
            let s = this.valueColumn.count;
            let t = a.f;
            let u = this.abt;
            let v = new ScalerParams(0, d, e, this.abt.ch, f);
            let w = this.u2;
            let x = this.acn;
            let y = this.u6;
            let z = this.aco || 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.ys.ak = x;
                        this.ys.ag = x;
                        this.ys.al = z;
                        this.ys.ah = z;
                        this.ys.f = true;
                        let ab = this.ys.aw(s, 0)[0];
                        if (r && a.m != null && 0 < a.m.count) {
                            ab = truncate(Math.round(a.m._inner[0]));
                        }
                        if (p) {
                            this.zz(t, 0, s, u, v, b.q, ab);
                        }
                        this.ys.ad(n, false, false, false, false);
                        n.ap = this.ys.k;
                        n.aq = this.ys.l;
                    }
                    else {
                        n = m.item(o);
                        o++;
                        c.dl(n, j, aa);
                        n.width = g;
                        n.height = Math.abs(aa - k);
                        this.ys.ak = w;
                        this.ys.ag = w;
                        this.ys.al = y;
                        this.ys.ah = y;
                        this.ys.f = false;
                        let ac = this.ys.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.zz(t, 0, s, u, v, b.q, ac);
                        }
                        this.ys.ad(n, false, false, false, false);
                        n.ap = this.ys.k;
                        n.aq = this.ys.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.ys.ak = w;
                    this.ys.ag = w;
                    this.ys.al = y;
                    this.ys.ah = y;
                    this.ys.f = false;
                    let ag = this.ys.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.zz(t, ad, s, u, v, b.q, ag);
                        }
                    }
                    else {
                        this.ys.ak = x;
                        this.ys.ag = x;
                        this.ys.al = z;
                        this.ys.ah = z;
                        this.ys.f = true;
                        if (p) {
                            this.zz(t, ad, s, u, v, b.q, ag);
                        }
                    }
                    this.ys.ad(n, false, false, false, false);
                    n.ap = this.ys.k;
                    n.aq = this.ys.l;
                    l = af;
                }
            }
            m.count = o;
            b.c3(a);
        }
        get useHighMarkerFidelity() {
            return this.zg;
        }
    }
    WaterfallSeries.$t = /*@__PURE__*/ markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
    WaterfallSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, WaterfallSeries, 'raisePropertyChanged', ['NegativeBrush:acn:acj', [Brush.$, null], 'NegativeOutline:aco:ack', [Brush.$, null], 'RadiusX:acd:acl', [1, 0], 'RadiusY:ace:acm', [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.w1 = Defaults.c;
                this.df.jn = Defaults.i;
                this.df.acn = Defaults.ah;
                this.df.aco = 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.u2)) {
                    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;
})();
