/*
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 { List$1 } from "igniteui-angular-core";
import { SeriesLayerPropertyOverlay } from "./SeriesLayerPropertyOverlay";
import { runOn, delegateCombine, markType, markDep, fromEnum } from "igniteui-angular-core";
import { Defaults } from "./Defaults";
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 { ScalerParams } from "./ScalerParams";
import { ChartSelection } from "./ChartSelection";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_ } from "igniteui-angular-core";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
import { BrushUtil } from "igniteui-angular-core";
/**
 * @hidden
 */
export let WaterfallSeries = /*@__PURE__*/ (() => {
    class WaterfallSeries extends HorizontalAnchoredCategorySeries {
        constructor() {
            super();
            this.ab = WaterfallSeries.$;
        }
        bk() {
            return new WaterfallSeries();
        }
        get_f7() {
            return true;
        }
        get_fm() {
            return true;
        }
        hu() {
            let a = super.hu();
            {
                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.r8));
                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.r8));
                a.add(c);
            }
            return a;
        }
        jn() {
            if (!isNaN_(this.jm)) {
                return super.jn();
            }
            return Defaults.h;
        }
        get_fc() {
            return true;
        }
        ct() {
            return new WaterfallSeriesView(this);
        }
        q7(a) {
            super.q7(a);
            this.ac8 = a;
        }
        preferredCategoryMode(a) {
            return 2;
        }
        get_fn() {
            return true;
        }
        sb(a, b) {
            super.sb(a, b);
            this.adj = a;
            this.adk = b;
        }
        v6() {
            return this.adj;
        }
        v7() {
            return this.adk;
        }
        cz() {
            if (this.c0 == 0) {
                return 2;
            }
            return super.cz();
        }
        get_ef() {
            return true;
        }
        rg(a, b, c, d) {
            super.rg(a, b, c, d);
            switch (b) {
                case WaterfallSeries.$$p[3]:
                case WaterfallSeries.$$p[2]:
                case WaterfallSeries.$$p[0]:
                case WaterfallSeries.$$p[1]:
                    this.ry(false);
                    break;
            }
        }
        gx(a, b) {
            if (this.g0(a, b)) {
                return true;
            }
            if (this.xr(a, b)) {
                return true;
            }
            return false;
        }
        wx(a) {
            if (this.ac8 == null || this.ac8.du == null || this.ac8.du.count == 0 || this.xAxis == null) {
                return Rect.empty;
            }
            let b = this.ac8.du;
            let c = this.wh(a);
            let d = -1;
            let e = this.xAxis.df;
            let f = this.w2.right * 2;
            if (e) {
                d = ArrayExtension.binarySearch$1(Rectangle.$, b, (g) => {
                    let h = this.ac8.d1(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.ac8.d1(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.adl(g);
            let j = this.adl(d);
            let k = this.adl(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;
        }
        adl(a) {
            return this.ac8.d0(a);
        }
        ze() {
            return 1;
        }
        pb(a, b) {
            super.pb(a, b);
            this.ac8.du.count = 0;
        }
        get_abn() {
            return 1;
        }
        iy() {
            return this.acp.ou(this.cw.ca, this.cw.b9, this.getEffectiveViewport1(this.cw));
        }
        aax(a, b) {
            let c = b;
            super.aax(a, b);
            let d = b.ca;
            let e = b.b9;
            let f = this.getEffectiveViewport1(b);
            let g = this.acp.ou(d, e, f);
            let h = this.ac9;
            let i = this.ada;
            let j;
            let k = this.abl(b);
            let l = NaN;
            let m = c.du;
            let n;
            let o = 0;
            this.zc.a2(this, this.zw(), runOn(this, this.yw), this.z5(b), this.z6(b));
            this.zc.r = this.ac9;
            this.zc.s = this.ada;
            this.zc.k = this.ac9;
            this.zc.l = this.ada;
            let p = false;
            let q = this.zc.b;
            if (q != null) {
                p = true;
            }
            let r = this.acp.dm;
            let s = this.valueColumn.count;
            let t = a.h;
            let u = this.acp;
            let v = new ScalerParams(0, d, e, this.acp.df, f);
            let w = this.vj;
            let x = this.adj;
            let y = this.vn;
            let z = this.adk || y;
            if (a.h.count > 0) {
                j = a.h._inner[0][0] - 0.5 * g;
                let aa = a.h._inner[0][1];
                if (!isNaN_(aa)) {
                    if (aa > k) {
                        n = m.item(o);
                        o++;
                        c.dz(n, j, k);
                        n.width = g;
                        n.height = Math.abs(k - aa);
                        this.zc.ak = x;
                        this.zc.ag = x;
                        this.zc.al = z;
                        this.zc.ah = z;
                        this.zc.f = true;
                        let ab = this.zc.aw(s, 0)[0];
                        if (r && a.o != null && 0 < a.o.count) {
                            ab = truncate(Math.round(a.o._inner[0]));
                        }
                        if (p) {
                            this.aat(t, 0, s, u, v, b.t, ab);
                        }
                        this.zc.ad(n, false, false, false, false);
                        n.ap = this.zc.k;
                        n.aq = this.zc.l;
                    }
                    else {
                        n = m.item(o);
                        o++;
                        c.dz(n, j, aa);
                        n.width = g;
                        n.height = Math.abs(aa - k);
                        this.zc.ak = w;
                        this.zc.ag = w;
                        this.zc.al = y;
                        this.zc.ah = y;
                        this.zc.f = false;
                        let ac = this.zc.aw(s, o)[0];
                        if (r && a.o != null && o >= 0 && o < a.o.count) {
                            ac = truncate(Math.round(a.o._inner[o]));
                        }
                        if (p) {
                            this.aat(t, 0, s, u, v, b.t, ac);
                        }
                        this.zc.ad(n, false, false, false, false);
                        n.ap = this.zc.k;
                        n.aq = this.zc.l;
                    }
                    l = aa;
                }
                else {
                    l = k;
                }
            }
            for (let ad = 1; ad < a.h.count; ++ad) {
                let ae = a.h._inner[ad];
                j = a.h._inner[ad][0] - 0.5 * g;
                let af = ae[1];
                if (!isNaN_(af)) {
                    n = m.item(o);
                    o++;
                    c.dz(n, j, Math.min(l, af));
                    n.width = g;
                    n.height = Math.abs(l - af);
                    this.zc.ak = w;
                    this.zc.ag = w;
                    this.zc.al = y;
                    this.zc.ah = y;
                    this.zc.f = false;
                    let ag = this.zc.aw(s, o)[0];
                    if (r && a.o != null && o >= 0 && o < a.o.count) {
                        ag = truncate(Math.round(a.o._inner[o]));
                    }
                    if (l > af) {
                        if (p) {
                            this.aat(t, ad, s, u, v, b.t, ag);
                        }
                    }
                    else {
                        this.zc.ak = x;
                        this.zc.ag = x;
                        this.zc.al = z;
                        this.zc.ah = z;
                        this.zc.f = true;
                        if (p) {
                            this.aat(t, ad, s, u, v, b.t, ag);
                        }
                    }
                    this.zc.ad(n, false, false, false, false);
                    n.ap = this.zc.k;
                    n.aq = this.zc.l;
                    l = af;
                }
            }
            m.count = o;
            b.dg(a);
        }
        qa(a, b, c) {
            this.aap(a, b, c, this.y3, 1);
        }
        ak(a, b) {
            let c = new List$1(ChartSelection.$, 0);
            this.qa(a, c, b);
            return c.toArray();
        }
        abg(a, b, c) {
            if (c == 0) {
                return 0 < b && a < this.valueColumn.item(c);
            }
            else {
                let d = this.valueColumn.item(c - 1);
                let e = Math.min(d, this.valueColumn.item(c));
                let f = Math.max(d, this.valueColumn.item(c));
                return e < b && a < f;
            }
        }
        get useHighMarkerFidelity() {
            return this.z0;
        }
    }
    WaterfallSeries.$t = markType(WaterfallSeries, 'WaterfallSeries', HorizontalAnchoredCategorySeries.$);
    WaterfallSeries.$$p = markDep(DependencyProperty, PropertyMetadata, WaterfallSeries, 'raisePropertyChanged', ['NegativeBrush:adj:adf', [Brush.$, null], 'NegativeOutline:adk:adg', [Brush.$, null], 'RadiusX:ac9:adh', [1, 0], 'RadiusY:ada:adi', [1, 0]]);
    return WaterfallSeries;
})();
/**
 * @hidden
 */
export let WaterfallSeriesView = /*@__PURE__*/ (() => {
    class WaterfallSeriesView extends AnchoredCategorySeriesView {
        constructor(a) {
            super(a);
            this.dt = null;
            this.dv = null;
            this.d2 = new Rectangle();
            this.du = null;
            this.dt = a;
            this.du = ((() => {
                let $ret = new Pool$1(Rectangle.$);
                $ret.create = runOn(this, this.d3);
                $ret.activate = runOn(this, this.dw);
                $ret.disactivate = runOn(this, this.dy);
                $ret.destroy = runOn(this, this.dx);
                return $ret;
            })());
        }
        a4() {
            super.a4();
            this.dv = new List$1(Rectangle.$, 0);
            if (!this.t) {
                this.dt.xk = Defaults.c;
                this.dt.jt = Defaults.i;
                this.dt.adj = Defaults.financialSeries_NegativeBrush;
                this.dt.adk = Defaults.financialSeries_NegativeOutline;
            }
        }
        d3() {
            let a = new Rectangle();
            this.dv.add(a);
            a._visibility = 1;
            return a;
        }
        dw(a) {
            a._visibility = 0;
        }
        dy(a) {
            a._visibility = 1;
        }
        dx(a) {
            this.dv.remove(a);
        }
        dz(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.a2();
            }
        }
        ak(a) {
            return this.dv._inner[a];
        }
        aj(a) {
            let b = this.dv._inner[a];
            this.d2._visibility = b._visibility;
            this.d2.n = b.n;
            this.d2.o = b.o;
            this.d2.width = b.width;
            this.d2.height = b.height;
            let c = this.b4(a);
            this.d2._fill = c;
            this.d2._stroke = c;
            this.d2.ad = this.f.ig + 3;
            return this.d2;
        }
        bj(a, b) {
            super.bj(a, b);
            if (a.d) {
                for (let c = 0; c < this.dv.count; c++) {
                    let d = this.ai(c, b);
                    this.br(d, c, b);
                    a.w(d);
                }
            }
        }
        ax(a) {
            super.ax(a);
            let b = 0;
            let c = new List$1(Rectangle.$, 0);
            for (let d of fromEnum(this.du.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.f.vj)) {
                    f = "Positive";
                }
                this.f.bc.exportRectangleData(a, e, "column" + b, ["Main", f]);
            }
            b++;
        }
        d0(a) {
            let b = this.du.item(a);
            return new Rect(0, b.n, b.o, b.width, b.height);
        }
        d1(a) {
            return new Rect(0, a.n, a.o, a.width, a.height);
        }
    }
    WaterfallSeriesView.$t = markType(WaterfallSeriesView, 'WaterfallSeriesView', AnchoredCategorySeriesView.$);
    return WaterfallSeriesView;
})();
