/*
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 class PriceChannelOverlay extends FinancialOverlay {
    constructor() {
        super();
        this.pp = new List$1(Number_$type, 0);
        this.po = new List$1(Number_$type, 0);
        this.ab = PriceChannelOverlay.$;
        this.mb = new CategoryFrame(3);
        this.md = new CategoryFrame(3);
        this.ma = new CategoryFrame(3);
    }
    iz(a, b, c, d) {
        switch (b) {
            case "HighColumn":
            case "LowColumn":
                this.pi = false;
                break;
        }
        super.iz(a, b, c, d);
        switch (b) {
            case PriceChannelOverlay.$$p[0]:
                this.pi = false;
                this.jd(false);
                break;
        }
    }
    dw(a, b, c) {
        let d = super.dw(a, b, c);
        if (this.my == null || this.m0 == null) {
            d = false;
        }
        return d;
    }
    pj() {
        this.pp.clear();
        this.po.clear();
        let a = truncate(MathUtil.b(this.pq, 0, this.bz.count));
        let b = Math.min(this.my.count, this.m0.count);
        let c = this.ns(this.my);
        let d = this.ns(this.m0);
        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.pp.add(g);
            this.po.add(h);
        }
        return true;
    }
    oz(a, b) {
        super.oz(a, b);
        let c = b.bs;
        let d = b.br;
        let e = this.getEffectiveViewport1(b);
        let f = new ScalerParams(0, c, d, this.l8.b8, e);
        let g = new ScalerParams(0, c, d, this.mt.b8, e);
        g.b = this.eh();
        let h = this.l8;
        let i = this.mt;
        a.f.clear();
        a.m.clear();
        a.p.clear();
        let j = 0;
        let k = typeCast(ISortingAxis_$type, this.l8);
        if (k != null && k.i$b.count != this.bz.count) {
            return;
        }
        j = this.nz(c, d, e);
        if (!this.pi) {
            this.pi = this.pj();
        }
        g.b = this.eh();
        let l = this.l8.dz(2, f) - this.l8.dz(1, f);
        for (let m = b.bu.c; m <= b.bu.d; ++m) {
            let n;
            if (k == null) {
                n = b.bu.getBucket(m);
            }
            else {
                let o = k.i$b._inner[m];
                let p = k.i$d(o);
                let q = this.pp._inner[m];
                let r = this.po._inner[m];
                let s = q;
                let t = r;
                let u = p;
                while (m < b.bu.d) {
                    o = k.i$b._inner[m + 1];
                    u = k.i$d(o);
                    if (u - p > l) {
                        break;
                    }
                    m++;
                    s = Math.max(q, this.pp._inner[m]);
                    t = Math.min(r, this.po._inner[m]);
                }
                if (!isInfinity(t) && !isInfinity(s)) {
                    let v = NaN;
                    if (!isNaN_(p)) {
                        v = this.l8.dw(p, f);
                    }
                    n = [v, t, s];
                }
                else {
                    n = [NaN, NaN, NaN];
                }
            }
            let w = Math.max(1, l);
            if (!isNaN_(n[0]) && m * w >= this.pk) {
                if (this.l8 != null && typeCast(ISortingAxis_$type, this.l8) !== null) {
                    n[0] = n[0] + j;
                }
                else {
                    n[0] = h.dw(n[0], f) + j;
                }
                n[1] = i.dw(n[1], g);
                n[2] = i.dw(n[2], g);
                a.f.add(n);
            }
        }
    }
    hv(a, b) {
        super.hv(a, b);
        let c = b;
        if (c != null) {
            c.b1();
        }
    }
    o1(a, b) {
        super.o1(a, b);
        let c = typeCast(PriceChannelOverlayView.$, b);
        if (c == null) {
            return;
        }
        let d = this.getEffectiveViewport1(b);
        if (b.bx(a)) {
            c.b1();
            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.b2(e, f, g, h, i);
            b.bz(a);
        }
        this.mg.x(this, this.ng(), this.l8, runOn(this, this.l0), this.n5(b), this.n7(b));
        let j = false;
        let k = this.mg.c;
        let l = a.f;
        let m = this.bz.count;
        if (k != null) {
            j = true;
        }
        if (j) {
            let n = new ScalerParams(0, b.bs, b.br, this.l8.b8, d);
            this.oy(l, -1, m, this.l8, n, b.n);
        }
        let o = c.b8;
        let p = c.b9;
        let q = c.b4;
        this.mg.ae(o, true, false, true, true);
        this.mg.ae(p, true, false, true, true);
        this.mg.ae(q, false, true, false, false);
        q._opacity = this.mg.i * this.d6;
    }
    bf() {
        return new PriceChannelOverlayView(this);
    }
    iu(a) {
        super.iu(a);
        this.pn = typeCast(PriceChannelOverlayView.$, a);
    }
    en(a, b, c) {
        if (this.bs == null) {
            return NaN;
        }
        let d = this.getEffectiveViewport1(this.bi);
        let e = new ScalerParams(0, this.bs.mq, this.bi.br, this.l8.b8, d);
        let f = this.nz(this.bs.mq, this.bi.br, d);
        return this.ep(new RangeValueList(this.pp, this.po), a, this.l8, e, f, runOn(this, this.ny), b, c);
    }
    fc(a, b) {
        if (this.pp == null || this.po == null) {
            return super.fc(a, b);
        }
        return this.fd(a, b, this.l8, runOn(this, this.ny), new RangeValueList(this.pp, this.po));
    }
    fe(a, b) {
        if (this.pp == null || this.po == null) {
            return super.fe(a, b);
        }
        return this.ff(a, b, this.l8, runOn(this, this.ny), new RangeValueList(this.pp, this.po));
    }
    eh() {
        return Series.ei(this.po, null);
    }
}
PriceChannelOverlay.$t = markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
PriceChannelOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:pq:ps', [1, 14]]);
/**
 * @hidden
 */
export 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.bw.bz.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.b0.pp._inner[g]) && !isNaN_(this.f.b0.po._inner[g])) {
                    d = Math.max(d, this.f.b0.pp._inner[g]);
                    e = Math.min(e, this.f.b0.po._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.$);
/**
 * @hidden
 */
export class PriceChannelOverlayView extends FinancialSeriesView {
    constructor(a) {
        super(a);
        this.b5 = new Polygon();
        this.ca = new Polyline();
        this.cb = new Polyline();
        this.b0 = null;
        this.b3 = new Polygon();
        this.b6 = new Polyline();
        this.b7 = new Polyline();
        this.b0 = a;
    }
    get b4() {
        return this.b5;
    }
    get b8() {
        return this.ca;
    }
    get b9() {
        return this.cb;
    }
    ap() {
        super.ap();
        if (!this.n) {
            this.e.bj = 1;
        }
    }
    bv() {
        return new PriceChannelBucketCalculator(this);
    }
    b1() {
        this.b5.ak.clear();
        this.ca.ak.clear();
        this.cb.ak.clear();
        this.an();
    }
    b2(a, b, c, d, e) {
        for (let f of fromEnum(Flattener.d(a, b, d, this.e.eu))) {
            this.b5.ak.add({ $type: Point_$type, x: b(f), y: d(f) });
            this.ca.ak.add({ $type: Point_$type, x: b(f), y: d(f) });
        }
        for (let g of fromEnum(Flattener.d(a, c, e, this.e.eu))) {
            this.b5.ak.add({ $type: Point_$type, x: c(g), y: e(g) });
            this.cb.ak.add({ $type: Point_$type, x: c(g), y: e(g) });
        }
        this.an();
    }
    a9() {
        super.a9();
        this.b3.ak = this.b5.ak;
        this.b6.ak = this.ca.ak;
        this.b7.ak = this.cb.ak;
        let a = this.bl();
        this.b3._fill = a;
        this.b3._opacity = 1;
        this.b6._stroke = a;
        this.b6.ac = this.e.ey + 3;
        this.b7._stroke = a;
        this.b7.ac = this.e.ey + 3;
    }
    a3(a, b) {
        super.a3(a, b);
        if (a.d) {
            if (b) {
                a.t(this.b3);
                a.u(this.b6);
                a.u(this.b7);
            }
            else {
                a.t(this.b5);
                a.u(this.ca);
                a.u(this.cb);
            }
        }
    }
    ai(a) {
        super.ai(a);
        this.e.a2.exportPolygonData(a, this.b5, "fill", ["Fill"]);
        this.e.a2.exportPolylineData(a, this.ca, "bottom", ["Lower", "Main"]);
        this.e.a2.exportPolylineData(a, this.cb, "top", ["Upper"]);
    }
}
PriceChannelOverlayView.$t = markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
//# sourceMappingURL=PriceChannelOverlay_combined.js.map