/*
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 { FinancialOverlay } from "./FinancialOverlay";
import { DependencyProperty } from "igniteui-angular-core";
import { Series } from "./Series";
import { List$1 } from "igniteui-angular-core";
import { Number_$type, typeCast, runOn, markType, markDep, Point_$type, fromEnum } from "igniteui-angular-core";
import { CategoryFrame } from "./CategoryFrame";
import { MathUtil } from "igniteui-angular-core";
import { FinancialSeriesView } from "./FinancialSeriesView";
import { ScalerParams } from "./ScalerParams";
import { ISortingAxis_$type } from "./ISortingAxis";
import { FinancialBucketCalculator } from "./FinancialBucketCalculator";
import { Polyline } from "igniteui-angular-core";
import { Polygon } from "igniteui-angular-core";
import { RangeValueList } from "./RangeValueList";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_, isInfinity } from "igniteui-angular-core";
import { Flattener } from "igniteui-angular-core";
/**
 * @hidden
 */
export let PriceChannelOverlay = /*@__PURE__*/ (() => {
    class PriceChannelOverlay extends FinancialOverlay {
        constructor() {
            super();
            this.abh = new List$1(Number_$type, 0);
            this.abg = new List$1(Number_$type, 0);
            this.ab = PriceChannelOverlay.$;
            this.xk = new CategoryFrame(3);
            this.xm = new CategoryFrame(3);
            this.xi = new CategoryFrame(3);
        }
        bk() {
            return new PriceChannelOverlay();
        }
        rg(a, b, c, d) {
            switch (b) {
                case "HighColumn":
                case "LowColumn":
                    this.aba = false;
                    break;
            }
            super.rg(a, b, c, d);
            switch (b) {
                case PriceChannelOverlay.$$p[0]:
                    this.aba = false;
                    this.ry(false);
                    break;
            }
        }
        hf(a, b, c) {
            let d = super.hf(a, b, c);
            if (this.ya == null || this.yb == null) {
                d = false;
            }
            return d;
        }
        abb() {
            this.abh.clear();
            this.abg.clear();
            let a = truncate(MathUtil.d(this.abi, 0, this.dp.count));
            let b = Math.min(this.ya.count, this.yb.count);
            let c = this.y0(this.ya);
            let d = this.y0(this.yb);
            for (let e = 0; e < b; e++) {
                let f = Math.min(a, e);
                let g = -1.7976931348623157E+308;
                let h = 1.7976931348623157E+308;
                for (let i = 0; i < f; i++) {
                    if (!isNaN_(c.item(e - i))) {
                        g = Math.max(g, c.item(e - i));
                    }
                    if (!isNaN_(d.item(e - i))) {
                        h = Math.min(h, d.item(e - i));
                    }
                }
                if (e == 0) {
                    h = d.item(0);
                    g = c.item(0);
                }
                this.abh.add(g);
                this.abg.add(h);
            }
            return true;
        }
        aam(a, b) {
            super.aam(a, b);
            let c = b.ca;
            let d = b.b9;
            let e = this.getEffectiveViewport1(b);
            let f = new ScalerParams(0, c, d, this.xg.df, e);
            let g = new ScalerParams(0, c, d, this.xz.df, e);
            g.b = this.i0();
            let h = this.xg;
            let i = this.xz;
            a.h.clear();
            a.p.clear();
            a.s.clear();
            let j = 0;
            let k = typeCast(ISortingAxis_$type, this.xg);
            if (k != null && k.i$b.count != this.dp.count) {
                return;
            }
            j = this.y7(c, d, e);
            if (!this.aba) {
                this.aba = this.abb();
            }
            g.b = this.i0();
            let l = this.xg.fw(2, f) - this.xg.fw(1, f);
            for (let m = b.cd.c; m <= b.cd.d; ++m) {
                let n;
                if (k == null) {
                    n = b.cd.getBucket(m);
                }
                else {
                    let o = k.i$b._inner[m];
                    let p = k.i$d(o);
                    let q = this.abh._inner[m];
                    let r = this.abg._inner[m];
                    let s = q;
                    let t = r;
                    let u = p;
                    while (m < b.cd.d) {
                        o = k.i$b._inner[m + 1];
                        u = k.i$d(o);
                        if (u - p > l) {
                            break;
                        }
                        m++;
                        s = Math.max(q, this.abh._inner[m]);
                        t = Math.min(r, this.abg._inner[m]);
                    }
                    if (!isInfinity(t) && !isInfinity(s)) {
                        let v = NaN;
                        if (!isNaN_(p)) {
                            v = this.xg.ft(p, f);
                        }
                        n = [v, t, s];
                    }
                    else {
                        n = [NaN, NaN, NaN];
                    }
                }
                let w = Math.max(1, l);
                if (!isNaN_(n[0]) && m * w >= this.abc) {
                    if (this.xg != null && typeCast(ISortingAxis_$type, this.xg) !== null) {
                        n[0] = n[0] + j;
                    }
                    else {
                        n[0] = h.ft(n[0], f) + j;
                    }
                    n[1] = i.ft(n[1], g);
                    n[2] = i.ft(n[2], g);
                    a.h.add(n);
                }
            }
        }
        pb(a, b) {
            super.pb(a, b);
            let c = b;
            if (c != null) {
                c.ck();
            }
        }
        aao(a, b) {
            super.aao(a, b);
            let c = typeCast(PriceChannelOverlayView.$, b);
            if (c == null) {
                return;
            }
            let d = this.getEffectiveViewport1(b);
            if (b.cg(a)) {
                c.ck();
                let e = a.h.count;
                let f = (g) => a.h._inner[g][0];
                let g = (h) => a.h._inner[e - 1 - h][0];
                let h = (i) => a.h._inner[i][1];
                let i = (j) => a.h._inner[e - 1 - j][2];
                c.cl(e, f, g, h, i);
                b.ci(a);
            }
            this.xp.a2(this, this.yo(), runOn(this, this.w8), this.zd(b), this.zf(b));
            let j = false;
            let k = this.xp.b;
            let l = a.h;
            let m = this.dp.count;
            if (k != null) {
                j = true;
            }
            if (j) {
                let n = new ScalerParams(0, b.ca, b.b9, this.xg.df, d);
                this.aal(l, -1, m, this.xg, n, b.t, -1);
            }
            let o = c.cr;
            let p = c.cs;
            let q = c.cn;
            this.xp.ad(o, true, false, true, true);
            this.xp.ad(p, true, false, true, true);
            this.xp.ad(q, false, true, false, false);
            q._opacity = this.xp.j * this.ia;
        }
        ct() {
            return new PriceChannelOverlayView(this);
        }
        q7(a) {
            super.q7(a);
            this.abf = typeCast(PriceChannelOverlayView.$, a);
        }
        i8(a, b, c) {
            if (this.dc == null) {
                return NaN;
            }
            let d = this.getEffectiveViewport1(this.cw);
            let e = new ScalerParams(0, this.dc.xm, this.cw.b9, this.xg.df, d);
            let f = this.y7(this.dc.xm, this.cw.b9, d);
            return this.ja(new RangeValueList(this.abh, this.abg), a, this.xg, e, f, runOn(this, this.y6), b, c);
        }
        kc(a, b) {
            if (this.abh == null || this.abg == null) {
                return super.kc(a, b);
            }
            return this.kd(a, b, this.xg, runOn(this, this.y6), new RangeValueList(this.abh, this.abg));
        }
        ke(a, b) {
            if (this.abh == null || this.abg == null) {
                return super.ke(a, b);
            }
            return this.kf(a, b, this.xg, runOn(this, this.y6), new RangeValueList(this.abh, this.abg));
        }
        i0() {
            return Series.i2(this.abg, null);
        }
    }
    PriceChannelOverlay.$t = markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:abi:abk', [1, 14]]);
    return PriceChannelOverlay;
})();
/**
 * @hidden
 */
export let PriceChannelBucketCalculator = /*@__PURE__*/ (() => {
    class PriceChannelBucketCalculator extends FinancialBucketCalculator {
        constructor(a) {
            super(a);
            this.f = null;
            this.f = a;
        }
        getBucket(a) {
            let b = a * this.b;
            let c = Math.min(b + this.b - 1, this.a.cf.dp.count - 1);
            if (b <= c) {
                let d = -1.7976931348623157E+308;
                let e = 1.7976931348623157E+308;
                let f = 0;
                for (let g = b; g <= c; ++g) {
                    if (!isNaN_(this.f.cj.abh._inner[g]) && !isNaN_(this.f.cj.abg._inner[g])) {
                        d = Math.max(d, this.f.cj.abh._inner[g]);
                        e = Math.min(e, this.f.cj.abg._inner[g]);
                        ++f;
                    }
                }
                if (f > 0 && e != 1.7976931348623157E+308 && d != -1.7976931348623157E+308) {
                    return [0.5 * (b + c), e, d];
                }
            }
            return [NaN, NaN, NaN];
        }
    }
    PriceChannelBucketCalculator.$t = markType(PriceChannelBucketCalculator, 'PriceChannelBucketCalculator', FinancialBucketCalculator.$);
    return PriceChannelBucketCalculator;
})();
/**
 * @hidden
 */
export let PriceChannelOverlayView = /*@__PURE__*/ (() => {
    class PriceChannelOverlayView extends FinancialSeriesView {
        constructor(a) {
            super(a);
            this.co = new Polygon();
            this.ct = new Polyline();
            this.cu = new Polyline();
            this.cj = null;
            this.cm = new Polygon();
            this.cp = new Polyline();
            this.cq = new Polyline();
            this.cj = a;
        }
        get cn() {
            return this.co;
        }
        get cr() {
            return this.ct;
        }
        get cs() {
            return this.cu;
        }
        a4() {
            super.a4();
            if (!this.t) {
            }
        }
        ce() {
            return new PriceChannelBucketCalculator(this);
        }
        ck() {
            this.co.an.clear();
            this.ct.an.clear();
            this.cu.an.clear();
            this.a2();
        }
        cl(a, b, c, d, e) {
            for (let f of fromEnum(Flattener.d(a, b, d, this.f.ie))) {
                this.co.an.add({ $type: Point_$type, x: b(f), y: d(f) });
                this.ct.an.add({ $type: Point_$type, x: b(f), y: d(f) });
            }
            for (let g of fromEnum(Flattener.d(a, c, e, this.f.ie))) {
                this.co.an.add({ $type: Point_$type, x: c(g), y: e(g) });
                this.cu.an.add({ $type: Point_$type, x: c(g), y: e(g) });
            }
            this.a2();
        }
        bq() {
            super.bq();
            this.cm.an = this.co.an;
            this.cp.an = this.ct.an;
            this.cq.an = this.cu.an;
            let a = this.b3();
            this.cm._fill = a;
            this.cm._opacity = 1;
            this.cp._stroke = a;
            this.cp.ad = this.f.ig + 3;
            this.cq._stroke = a;
            this.cq.ad = this.f.ig + 3;
        }
        bj(a, b) {
            super.bj(a, b);
            if (a.d) {
                if (b) {
                    a.u(this.cm);
                    a.v(this.cp);
                    a.v(this.cq);
                }
                else {
                    a.u(this.co);
                    a.v(this.ct);
                    a.v(this.cu);
                }
            }
        }
        ax(a) {
            super.ax(a);
            this.f.bc.exportPolygonData(a, this.co, "fill", ["Fill"]);
            this.f.bc.exportPolylineData(a, this.ct, "bottom", ["Lower", "Main"]);
            this.f.bc.exportPolylineData(a, this.cu, "top", ["Upper"]);
        }
    }
    PriceChannelOverlayView.$t = markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
    return PriceChannelOverlayView;
})();
