/*
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 { 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 { Series } from "./Series";
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.t1 = new List$1(Number_$type, 0);
            this.t0 = new List$1(Number_$type, 0);
            this.ab = PriceChannelOverlay.$;
            this.qo = new CategoryFrame(3);
            this.qq = new CategoryFrame(3);
            this.qm = new CategoryFrame(3);
        }
        l9(a, b, c, d) {
            switch (b) {
                case "HighColumn":
                case "LowColumn":
                    this.tu = false;
                    break;
            }
            super.l9(a, b, c, d);
            switch (b) {
                case PriceChannelOverlay.$$p[0]:
                    this.tu = false;
                    this.mn(false);
                    break;
            }
        }
        fd(a, b, c) {
            let d = super.fd(a, b, c);
            if (this.re == null || this.rf == null) {
                d = false;
            }
            return d;
        }
        tv() {
            this.t1.clear();
            this.t0.clear();
            let a = truncate(MathUtil.d(this.t2, 0, this.cl.count));
            let b = Math.min(this.re.count, this.rf.count);
            let c = this.r4(this.re);
            let d = this.r4(this.rf);
            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.t1.add(g);
                this.t0.add(h);
            }
            return true;
        }
        tb(a, b) {
            super.tb(a, b);
            let c = b.bv;
            let d = b.bu;
            let e = this.getEffectiveViewport1(b);
            let f = new ScalerParams(0, c, d, this.qk.cg, e);
            let g = new ScalerParams(0, c, d, this.q6.cg, e);
            g.b = this.gg();
            let h = this.qk;
            let i = this.q6;
            a.f.clear();
            a.m.clear();
            a.p.clear();
            let j = 0;
            let k = typeCast(ISortingAxis_$type, this.qk);
            if (k != null && k.i$b.count != this.cl.count) {
                return;
            }
            j = this.sb(c, d, e);
            if (!this.tu) {
                this.tu = this.tv();
            }
            g.b = this.gg();
            let l = this.qk.el(2, f) - this.qk.el(1, f);
            for (let m = b.bx.c; m <= b.bx.d; ++m) {
                let n;
                if (k == null) {
                    n = b.bx.getBucket(m);
                }
                else {
                    let o = k.i$b._inner[m];
                    let p = k.i$d(o);
                    let q = this.t1._inner[m];
                    let r = this.t0._inner[m];
                    let s = q;
                    let t = r;
                    let u = p;
                    while (m < b.bx.d) {
                        o = k.i$b._inner[m + 1];
                        u = k.i$d(o);
                        if (u - p > l) {
                            break;
                        }
                        m++;
                        s = Math.max(q, this.t1._inner[m]);
                        t = Math.min(r, this.t0._inner[m]);
                    }
                    if (!isInfinity(t) && !isInfinity(s)) {
                        let v = NaN;
                        if (!isNaN_(p)) {
                            v = this.qk.ei(p, f);
                        }
                        n = [v, t, s];
                    }
                    else {
                        n = [NaN, NaN, NaN];
                    }
                }
                let w = Math.max(1, l);
                if (!isNaN_(n[0]) && m * w >= this.tw) {
                    if (this.qk != null && typeCast(ISortingAxis_$type, this.qk) !== null) {
                        n[0] = n[0] + j;
                    }
                    else {
                        n[0] = h.ei(n[0], f) + j;
                    }
                    n[1] = i.ei(n[1], g);
                    n[2] = i.ei(n[2], g);
                    a.f.add(n);
                }
            }
        }
        k2(a, b) {
            super.k2(a, b);
            let c = b;
            if (c != null) {
                c.b4();
            }
        }
        td(a, b) {
            super.td(a, b);
            let c = typeCast(PriceChannelOverlayView.$, b);
            if (c == null) {
                return;
            }
            let d = this.getEffectiveViewport1(b);
            if (b.b0(a)) {
                c.b4();
                let e = a.f.count;
                let f = (g) => a.f._inner[g][0];
                let g = (h) => a.f._inner[e - 1 - h][0];
                let h = (i) => a.f._inner[i][1];
                let i = (j) => a.f._inner[e - 1 - j][2];
                c.b5(e, f, g, h, i);
                b.b2(a);
            }
            this.qt.a2(this, this.rs(), runOn(this, this.qc), this.sh(b), this.sj(b));
            let j = false;
            let k = this.qt.b;
            let l = a.f;
            let m = this.cl.count;
            if (k != null) {
                j = true;
            }
            if (j) {
                let n = new ScalerParams(0, b.bv, b.bu, this.qk.cg, d);
                this.ta(l, -1, m, this.qk, n, b.q);
            }
            let o = c.cb;
            let p = c.cc;
            let q = c.b7;
            this.qt.ad(o, true, false, true, true);
            this.qt.ad(p, true, false, true, true);
            this.qt.ad(q, false, true, false, false);
            q._opacity = this.qt.j * this.fu;
        }
        by() {
            return new PriceChannelOverlayView(this);
        }
        l4(a) {
            super.l4(a);
            this.tz = typeCast(PriceChannelOverlayView.$, a);
        }
        gn(a, b, c) {
            if (this.ce == null) {
                return NaN;
            }
            let d = this.getEffectiveViewport1(this.b1);
            let e = new ScalerParams(0, this.ce.ta, this.b1.bu, this.qk.cg, d);
            let f = this.sb(this.ce.ta, this.b1.bu, d);
            return this.gp(new RangeValueList(this.t1, this.t0), a, this.qk, e, f, runOn(this, this.sa), b, c);
        }
        hm(a, b) {
            if (this.t1 == null || this.t0 == null) {
                return super.hm(a, b);
            }
            return this.hn(a, b, this.qk, runOn(this, this.sa), new RangeValueList(this.t1, this.t0));
        }
        ho(a, b) {
            if (this.t1 == null || this.t0 == null) {
                return super.ho(a, b);
            }
            return this.hp(a, b, this.qk, runOn(this, this.sa), new RangeValueList(this.t1, this.t0));
        }
        gg() {
            return Series.gi(this.t0, null);
        }
    }
    PriceChannelOverlay.$t = markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:t2:t4', [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.bz.cl.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.b3.t1._inner[g]) && !isNaN_(this.f.b3.t0._inner[g])) {
                        d = Math.max(d, this.f.b3.t1._inner[g]);
                        e = Math.min(e, this.f.b3.t0._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.b8 = new Polygon();
            this.cd = new Polyline();
            this.ce = new Polyline();
            this.b3 = null;
            this.b6 = new Polygon();
            this.b9 = new Polyline();
            this.ca = new Polyline();
            this.b3 = a;
        }
        get b7() {
            return this.b8;
        }
        get cb() {
            return this.cd;
        }
        get cc() {
            return this.ce;
        }
        as() {
            super.as();
            if (!this.q) {
            }
        }
        by() {
            return new PriceChannelBucketCalculator(this);
        }
        b4() {
            this.b8.an.clear();
            this.cd.an.clear();
            this.ce.an.clear();
            this.aq();
        }
        b5(a, b, c, d, e) {
            for (let f of fromEnum(Flattener.d(a, b, d, this.e.fx))) {
                this.b8.an.add({ $type: Point_$type, x: b(f), y: d(f) });
                this.cd.an.add({ $type: Point_$type, x: b(f), y: d(f) });
            }
            for (let g of fromEnum(Flattener.d(a, c, e, this.e.fx))) {
                this.b8.an.add({ $type: Point_$type, x: c(g), y: e(g) });
                this.ce.an.add({ $type: Point_$type, x: c(g), y: e(g) });
            }
            this.aq();
        }
        bc() {
            super.bc();
            this.b6.an = this.b8.an;
            this.b9.an = this.cd.an;
            this.ca.an = this.ce.an;
            let a = this.bo();
            this.b6._fill = a;
            this.b6._opacity = 1;
            this.b9._stroke = a;
            this.b9.ad = this.e.fy + 3;
            this.ca._stroke = a;
            this.ca.ad = this.e.fy + 3;
        }
        a6(a, b) {
            super.a6(a, b);
            if (a.d) {
                if (b) {
                    a.u(this.b6);
                    a.v(this.b9);
                    a.v(this.ca);
                }
                else {
                    a.u(this.b8);
                    a.v(this.cd);
                    a.v(this.ce);
                }
            }
        }
        al(a) {
            super.al(a);
            this.e.a9.exportPolygonData(a, this.b8, "fill", ["Fill"]);
            this.e.a9.exportPolylineData(a, this.cd, "bottom", ["Lower", "Main"]);
            this.e.a9.exportPolylineData(a, this.ce, "top", ["Upper"]);
        }
    }
    PriceChannelOverlayView.$t = markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
    return PriceChannelOverlayView;
})();
