/*
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.ts = new List$1(Number_$type, 0);
            this.tr = new List$1(Number_$type, 0);
            this.ab = PriceChannelOverlay.$;
            this.qf = new CategoryFrame(3);
            this.qh = new CategoryFrame(3);
            this.qd = new CategoryFrame(3);
        }
        l3(a, b, c, d) {
            switch (b) {
                case "HighColumn":
                case "LowColumn":
                    this.tl = false;
                    break;
            }
            super.l3(a, b, c, d);
            switch (b) {
                case PriceChannelOverlay.$$p[0]:
                    this.tl = false;
                    this.mh(false);
                    break;
            }
        }
        e9(a, b, c) {
            let d = super.e9(a, b, c);
            if (this.q5 == null || this.q6 == null) {
                d = false;
            }
            return d;
        }
        tm() {
            this.ts.clear();
            this.tr.clear();
            let a = truncate(MathUtil.c(this.tt, 0, this.ck.count));
            let b = Math.min(this.q5.count, this.q6.count);
            let c = this.rv(this.q5);
            let d = this.rv(this.q6);
            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.ts.add(g);
                this.tr.add(h);
            }
            return true;
        }
        s2(a, b) {
            super.s2(a, b);
            let c = b.bv;
            let d = b.bu;
            let e = this.getEffectiveViewport1(b);
            let f = new ScalerParams(0, c, d, this.qb.cg, e);
            let g = new ScalerParams(0, c, d, this.qx.cg, e);
            g.b = this.gc();
            let h = this.qb;
            let i = this.qx;
            a.f.clear();
            a.m.clear();
            a.p.clear();
            let j = 0;
            let k = typeCast(ISortingAxis_$type, this.qb);
            if (k != null && k.i$b.count != this.ck.count) {
                return;
            }
            j = this.r2(c, d, e);
            if (!this.tl) {
                this.tl = this.tm();
            }
            g.b = this.gc();
            let l = this.qb.el(2, f) - this.qb.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.ts._inner[m];
                    let r = this.tr._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.ts._inner[m]);
                        t = Math.min(r, this.tr._inner[m]);
                    }
                    if (!isInfinity(t) && !isInfinity(s)) {
                        let v = NaN;
                        if (!isNaN_(p)) {
                            v = this.qb.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.tn) {
                    if (this.qb != null && typeCast(ISortingAxis_$type, this.qb) !== 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);
                }
            }
        }
        kx(a, b) {
            super.kx(a, b);
            let c = b;
            if (c != null) {
                c.b4();
            }
        }
        s4(a, b) {
            super.s4(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.qk.a0(this, this.rj(), runOn(this, this.p3), this.r8(b), this.sa(b));
            let j = false;
            let k = this.qk.b;
            let l = a.f;
            let m = this.ck.count;
            if (k != null) {
                j = true;
            }
            if (j) {
                let n = new ScalerParams(0, b.bv, b.bu, this.qb.cg, d);
                this.s1(l, -1, m, this.qb, n, b.q);
            }
            let o = c.cb;
            let p = c.cc;
            let q = c.b7;
            this.qk.ad(o, true, false, true, true);
            this.qk.ad(p, true, false, true, true);
            this.qk.ad(q, false, true, false, false);
            q._opacity = this.qk.j * this.fq;
        }
        bx() {
            return new PriceChannelOverlayView(this);
        }
        ly(a) {
            super.ly(a);
            this.tq = typeCast(PriceChannelOverlayView.$, a);
        }
        gj(a, b, c) {
            if (this.cd == null) {
                return NaN;
            }
            let d = this.getEffectiveViewport1(this.b0);
            let e = new ScalerParams(0, this.cd.sf, this.b0.bu, this.qb.cg, d);
            let f = this.r2(this.cd.sf, this.b0.bu, d);
            return this.gl(new RangeValueList(this.ts, this.tr), a, this.qb, e, f, runOn(this, this.r1), b, c);
        }
        hh(a, b) {
            if (this.ts == null || this.tr == null) {
                return super.hh(a, b);
            }
            return this.hi(a, b, this.qb, runOn(this, this.r1), new RangeValueList(this.ts, this.tr));
        }
        hj(a, b) {
            if (this.ts == null || this.tr == null) {
                return super.hj(a, b);
            }
            return this.hk(a, b, this.qb, runOn(this, this.r1), new RangeValueList(this.ts, this.tr));
        }
        gc() {
            return Series.ge(this.tr, null);
        }
    }
    PriceChannelOverlay.$t = markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:tt:tv', [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.ck.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.ts._inner[g]) && !isNaN_(this.f.b3.tr._inner[g])) {
                        d = Math.max(d, this.f.b3.ts._inner[g]);
                        e = Math.min(e, this.f.b3.tr._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.ak.clear();
            this.cd.ak.clear();
            this.ce.ak.clear();
            this.aq();
        }
        b5(a, b, c, d, e) {
            for (let f of fromEnum(Flattener.d(a, b, d, this.e.ft))) {
                this.b8.ak.add({ $type: Point_$type, x: b(f), y: d(f) });
                this.cd.ak.add({ $type: Point_$type, x: b(f), y: d(f) });
            }
            for (let g of fromEnum(Flattener.d(a, c, e, this.e.ft))) {
                this.b8.ak.add({ $type: Point_$type, x: c(g), y: e(g) });
                this.ce.ak.add({ $type: Point_$type, x: c(g), y: e(g) });
            }
            this.aq();
        }
        bc() {
            super.bc();
            this.b6.ak = this.b8.ak;
            this.b9.ak = this.cd.ak;
            this.ca.ak = this.ce.ak;
            let a = this.bo();
            this.b6._fill = a;
            this.b6._opacity = 1;
            this.b9._stroke = a;
            this.b9.ac = this.e.fu + 3;
            this.ca._stroke = a;
            this.ca.ac = this.e.fu + 3;
        }
        a6(a, b) {
            super.a6(a, b);
            if (a.d) {
                if (b) {
                    a.t(this.b6);
                    a.u(this.b9);
                    a.u(this.ca);
                }
                else {
                    a.t(this.b8);
                    a.u(this.cd);
                    a.u(this.ce);
                }
            }
        }
        al(a) {
            super.al(a);
            this.e.a8.exportPolygonData(a, this.b8, "fill", ["Fill"]);
            this.e.a8.exportPolylineData(a, this.cd, "bottom", ["Lower", "Main"]);
            this.e.a8.exportPolylineData(a, this.ce, "top", ["Upper"]);
        }
    }
    PriceChannelOverlayView.$t = markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
    return PriceChannelOverlayView;
})();
