/*
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-react-core";
import { Series } from "./Series";
import { List$1 } from "igniteui-react-core";
import { Number_$type, typeCast, runOn, markType, markDep, Point_$type, fromEnum } from "igniteui-react-core";
import { CategoryFrame } from "./CategoryFrame";
import { MathUtil } from "igniteui-react-core";
import { FinancialSeriesView } from "./FinancialSeriesView";
import { ScalerParams } from "./ScalerParams";
import { ISortingAxis_$type } from "./ISortingAxis";
import { FinancialBucketCalculator } from "./FinancialBucketCalculator";
import { Polyline } from "igniteui-react-core";
import { Polygon } from "igniteui-react-core";
import { RangeValueList } from "./RangeValueList";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity } from "igniteui-react-core";
import { Flattener } from "igniteui-react-core";
/**
 * @hidden
 */
export let PriceChannelOverlay = /*@__PURE__*/ (() => {
    class PriceChannelOverlay extends FinancialOverlay {
        bi() {
            return new PriceChannelOverlay();
        }
        constructor() {
            super();
            this.aay = new List$1(Number_$type, 0);
            this.aax = new List$1(Number_$type, 0);
            this.ab = PriceChannelOverlay.$;
            this.w1 = new CategoryFrame(3);
            this.w3 = new CategoryFrame(3);
            this.wz = new CategoryFrame(3);
        }
        q4(a, b, c, d) {
            switch (b) {
                case "HighColumn":
                case "LowColumn":
                    this.aar = false;
                    break;
            }
            super.q4(a, b, c, d);
            switch (b) {
                case PriceChannelOverlay.$$p[0]:
                    this.aar = false;
                    this.rm(false);
                    break;
            }
        }
        hc(a, b, c) {
            let d = super.hc(a, b, c);
            if (this.xr == null || this.xs == null) {
                d = false;
            }
            return d;
        }
        aas() {
            this.aay.clear();
            this.aax.clear();
            let a = truncate(MathUtil.d(this.aaz, 0, this.dl.count));
            let b = Math.min(this.xr.count, this.xs.count);
            let c = this.yh(this.xr);
            let d = this.yh(this.xs);
            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.aay.add(g);
                this.aax.add(h);
            }
            return true;
        }
        z3(a, b) {
            super.z3(a, b);
            let c = b.by;
            let d = b.bx;
            let e = this.getEffectiveViewport1(b);
            let f = new ScalerParams(0, c, d, this.wx.ch, e);
            let g = new ScalerParams(0, c, d, this.xg.ch, e);
            g.b = this.iw();
            let h = this.wx;
            let i = this.xg;
            a.f.clear();
            a.n.clear();
            a.q.clear();
            let j = 0;
            let k = typeCast(ISortingAxis_$type, this.wx);
            if (k != null && k.i$b.count != this.dl.count) {
                return;
            }
            j = this.yo(c, d, e);
            if (!this.aar) {
                this.aar = this.aas();
            }
            g.b = this.iw();
            let l = this.wx.en(2, f) - this.wx.en(1, f);
            for (let m = b.b0.c; m <= b.b0.d; ++m) {
                let n;
                if (k == null) {
                    n = b.b0.getBucket(m);
                }
                else {
                    let o = k.i$b._inner[m];
                    let p = k.i$d(o);
                    let q = this.aay._inner[m];
                    let r = this.aax._inner[m];
                    let s = q;
                    let t = r;
                    let u = p;
                    while (m < b.b0.d) {
                        o = k.i$b._inner[m + 1];
                        u = k.i$d(o);
                        if (u - p > l) {
                            break;
                        }
                        m++;
                        s = Math.max(q, this.aay._inner[m]);
                        t = Math.min(r, this.aax._inner[m]);
                    }
                    if (!isInfinity(t) && !isInfinity(s)) {
                        let v = NaN;
                        if (!isNaN_(p)) {
                            v = this.wx.ek(p, f);
                        }
                        n = [v, t, s];
                    }
                    else {
                        n = [NaN, NaN, NaN];
                    }
                }
                let w = Math.max(1, l);
                if (!isNaN_(n[0]) && m * w >= this.aat) {
                    if (this.wx != null && typeCast(ISortingAxis_$type, this.wx) !== null) {
                        n[0] = n[0] + j;
                    }
                    else {
                        n[0] = h.ek(n[0], f) + j;
                    }
                    n[1] = i.ek(n[1], g);
                    n[2] = i.ek(n[2], g);
                    a.f.add(n);
                }
            }
        }
        o2(a, b) {
            super.o2(a, b);
            let c = b;
            if (c != null) {
                c.b7();
            }
        }
        z5(a, b) {
            super.z5(a, b);
            let c = typeCast(PriceChannelOverlayView.$, b);
            if (c == null) {
                return;
            }
            let d = this.getEffectiveViewport1(b);
            if (b.b3(a)) {
                c.b7();
                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.b8(e, f, g, h, i);
                b.b5(a);
            }
            this.w6.a2(this, this.x5(), runOn(this, this.wp), this.yu(b), this.yw(b));
            let j = false;
            let k = this.w6.b;
            let l = a.f;
            let m = this.dl.count;
            if (k != null) {
                j = true;
            }
            if (j) {
                let n = new ScalerParams(0, b.by, b.bx, this.wx.ch, d);
                this.z2(l, -1, m, this.wx, n, b.q, -1);
            }
            let o = c.ce;
            let p = c.cf;
            let q = c.ca;
            this.w6.ad(o, true, false, true, true);
            this.w6.ad(p, true, false, true, true);
            this.w6.ad(q, false, true, false, false);
            q._opacity = this.w6.j * this.h7;
        }
        cq() {
            return new PriceChannelOverlayView(this);
        }
        qw(a) {
            super.qw(a);
            this.aaw = typeCast(PriceChannelOverlayView.$, a);
        }
        i3(a, b, c) {
            if (this.c9 == null) {
                return NaN;
            }
            let d = this.getEffectiveViewport1(this.ct);
            let e = new ScalerParams(0, this.c9.vl, this.ct.bx, this.wx.ch, d);
            let f = this.yo(this.c9.vl, this.ct.bx, d);
            return this.i5(new RangeValueList(this.aay, this.aax), a, this.wx, e, f, runOn(this, this.yn), b, c);
        }
        j6(a, b) {
            if (this.aay == null || this.aax == null) {
                return super.j6(a, b);
            }
            return this.j7(a, b, this.wx, runOn(this, this.yn), new RangeValueList(this.aay, this.aax));
        }
        j8(a, b) {
            if (this.aay == null || this.aax == null) {
                return super.j8(a, b);
            }
            return this.j9(a, b, this.wx, runOn(this, this.yn), new RangeValueList(this.aay, this.aax));
        }
        iw() {
            return Series.iy(this.aax, null);
        }
    }
    PriceChannelOverlay.$t = /*@__PURE__*/ markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:aaz:aa1', [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.b2.dl.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.b6.aay._inner[g]) && !isNaN_(this.f.b6.aax._inner[g])) {
                        d = Math.max(d, this.f.b6.aay._inner[g]);
                        e = Math.min(e, this.f.b6.aax._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 = /*@__PURE__*/ markType(PriceChannelBucketCalculator, 'PriceChannelBucketCalculator', FinancialBucketCalculator.$);
    return PriceChannelBucketCalculator;
})();
/**
 * @hidden
 */
export let PriceChannelOverlayView = /*@__PURE__*/ (() => {
    class PriceChannelOverlayView extends FinancialSeriesView {
        get ca() {
            return this.cb;
        }
        get ce() {
            return this.cg;
        }
        get cf() {
            return this.ch;
        }
        constructor(a) {
            super(a);
            this.cb = new Polygon();
            this.cg = new Polyline();
            this.ch = new Polyline();
            this.b6 = null;
            this.b9 = new Polygon();
            this.cc = new Polyline();
            this.cd = new Polyline();
            this.b6 = a;
        }
        au() {
            super.au();
            if (!this.q) {
            }
        }
        b1() {
            return new PriceChannelBucketCalculator(this);
        }
        b7() {
            this.cb.an.clear();
            this.cg.an.clear();
            this.ch.an.clear();
            this.as();
        }
        b8(a, b, c, d, e) {
            for (let f of fromEnum(Flattener.d(a, b, d, this.e.ib))) {
                this.cb.an.add({ $type: Point_$type, x: b(f), y: d(f) });
                this.cg.an.add({ $type: Point_$type, x: b(f), y: d(f) });
            }
            for (let g of fromEnum(Flattener.d(a, c, e, this.e.ib))) {
                this.cb.an.add({ $type: Point_$type, x: c(g), y: e(g) });
                this.ch.an.add({ $type: Point_$type, x: c(g), y: e(g) });
            }
            this.as();
        }
        be() {
            super.be();
            this.b9.an = this.cb.an;
            this.cc.an = this.cg.an;
            this.cd.an = this.ch.an;
            let a = this.br();
            this.b9._fill = a;
            this.b9._opacity = 1;
            this.cc._stroke = a;
            this.cc.ad = this.e.ic + 3;
            this.cd._stroke = a;
            this.cd.ad = this.e.ic + 3;
        }
        a8(a, b) {
            super.a8(a, b);
            if (a.d) {
                if (b) {
                    a.u(this.b9);
                    a.v(this.cc);
                    a.v(this.cd);
                }
                else {
                    a.u(this.cb);
                    a.v(this.cg);
                    a.v(this.ch);
                }
            }
        }
        an(a) {
            super.an(a);
            this.e.bb.exportPolygonData(a, this.cb, "fill", ["Fill"]);
            this.e.bb.exportPolylineData(a, this.cg, "bottom", ["Lower", "Main"]);
            this.e.bb.exportPolylineData(a, this.ch, "top", ["Upper"]);
        }
    }
    PriceChannelOverlayView.$t = /*@__PURE__*/ markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
    return PriceChannelOverlayView;
})();
