/*
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 {
        bj() {
            return new PriceChannelOverlay();
        }
        constructor() {
            super();
            this.aa5 = new List$1(Number_$type, 0);
            this.aa4 = new List$1(Number_$type, 0);
            this.ab = PriceChannelOverlay.$;
            this.w8 = new CategoryFrame(3);
            this.xa = new CategoryFrame(3);
            this.w6 = new CategoryFrame(3);
        }
        q7(a, b, c, d) {
            switch (b) {
                case "HighColumn":
                case "LowColumn":
                    this.aay = false;
                    break;
            }
            super.q7(a, b, c, d);
            switch (b) {
                case PriceChannelOverlay.$$p[0]:
                    this.aay = false;
                    this.rp(false);
                    break;
            }
        }
        he(a, b, c) {
            let d = super.he(a, b, c);
            if (this.xy == null || this.xz == null) {
                d = false;
            }
            return d;
        }
        aaz() {
            this.aa5.clear();
            this.aa4.clear();
            let a = truncate(MathUtil.d(this.aa6, 0, this.dn.count));
            let b = Math.min(this.xy.count, this.xz.count);
            let c = this.yo(this.xy);
            let d = this.yo(this.xz);
            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.aa5.add(g);
                this.aa4.add(h);
            }
            return true;
        }
        aaa(a, b) {
            super.aaa(a, b);
            let c = b.by;
            let d = b.bx;
            let e = this.getEffectiveViewport1(b);
            let f = new ScalerParams(0, c, d, this.w4.ch, e);
            let g = new ScalerParams(0, c, d, this.xn.ch, e);
            g.b = this.iy();
            let h = this.w4;
            let i = this.xn;
            a.f.clear();
            a.n.clear();
            a.q.clear();
            let j = 0;
            let k = typeCast(ISortingAxis_$type, this.w4);
            if (k != null && k.i$b.count != this.dn.count) {
                return;
            }
            j = this.yv(c, d, e);
            if (!this.aay) {
                this.aay = this.aaz();
            }
            g.b = this.iy();
            let l = this.w4.eo(2, f) - this.w4.eo(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.aa5._inner[m];
                    let r = this.aa4._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.aa5._inner[m]);
                        t = Math.min(r, this.aa4._inner[m]);
                    }
                    if (!isInfinity(t) && !isInfinity(s)) {
                        let v = NaN;
                        if (!isNaN_(p)) {
                            v = this.w4.el(p, f);
                        }
                        n = [v, t, s];
                    }
                    else {
                        n = [NaN, NaN, NaN];
                    }
                }
                let w = Math.max(1, l);
                if (!isNaN_(n[0]) && m * w >= this.aa0) {
                    if (this.w4 != null && typeCast(ISortingAxis_$type, this.w4) !== null) {
                        n[0] = n[0] + j;
                    }
                    else {
                        n[0] = h.el(n[0], f) + j;
                    }
                    n[1] = i.el(n[1], g);
                    n[2] = i.el(n[2], g);
                    a.f.add(n);
                }
            }
        }
        o5(a, b) {
            super.o5(a, b);
            let c = b;
            if (c != null) {
                c.b7();
            }
        }
        aac(a, b) {
            super.aac(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.xd.a2(this, this.yc(), runOn(this, this.ww), this.y1(b), this.y3(b));
            let j = false;
            let k = this.xd.b;
            let l = a.f;
            let m = this.dn.count;
            if (k != null) {
                j = true;
            }
            if (j) {
                let n = new ScalerParams(0, b.by, b.bx, this.w4.ch, d);
                this.z9(l, -1, m, this.w4, n, b.q, -1);
            }
            let o = c.ce;
            let p = c.cf;
            let q = c.ca;
            this.xd.ad(o, true, false, true, true);
            this.xd.ad(p, true, false, true, true);
            this.xd.ad(q, false, true, false, false);
            q._opacity = this.xd.j * this.h9;
        }
        cs() {
            return new PriceChannelOverlayView(this);
        }
        qz(a) {
            super.qz(a);
            this.aa3 = typeCast(PriceChannelOverlayView.$, a);
        }
        i5(a, b, c) {
            if (this.db == null) {
                return NaN;
            }
            let d = this.getEffectiveViewport1(this.cv);
            let e = new ScalerParams(0, this.db.v4, this.cv.bx, this.w4.ch, d);
            let f = this.yv(this.db.v4, this.cv.bx, d);
            return this.i7(new RangeValueList(this.aa5, this.aa4), a, this.w4, e, f, runOn(this, this.yu), b, c);
        }
        j8(a, b) {
            if (this.aa5 == null || this.aa4 == null) {
                return super.j8(a, b);
            }
            return this.j9(a, b, this.w4, runOn(this, this.yu), new RangeValueList(this.aa5, this.aa4));
        }
        ka(a, b) {
            if (this.aa5 == null || this.aa4 == null) {
                return super.ka(a, b);
            }
            return this.kb(a, b, this.w4, runOn(this, this.yu), new RangeValueList(this.aa5, this.aa4));
        }
        iy() {
            return Series.i0(this.aa4, null);
        }
    }
    PriceChannelOverlay.$t = /*@__PURE__*/ markType(PriceChannelOverlay, 'PriceChannelOverlay', FinancialOverlay.$);
    PriceChannelOverlay.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, PriceChannelOverlay, 'raisePropertyChanged', ['Period:aa6:aa8', [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.dn.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.aa5._inner[g]) && !isNaN_(this.f.b6.aa4._inner[g])) {
                        d = Math.max(d, this.f.b6.aa5._inner[g]);
                        e = Math.min(e, this.f.b6.aa4._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.id))) {
                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.id))) {
                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.ie + 3;
            this.cd._stroke = a;
            this.cd.ad = this.e.ie + 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.bc.exportPolygonData(a, this.cb, "fill", ["Fill"]);
            this.e.bc.exportPolylineData(a, this.cg, "bottom", ["Lower", "Main"]);
            this.e.bc.exportPolylineData(a, this.ch, "top", ["Upper"]);
        }
    }
    PriceChannelOverlayView.$t = /*@__PURE__*/ markType(PriceChannelOverlayView, 'PriceChannelOverlayView', FinancialSeriesView.$);
    return PriceChannelOverlayView;
})();
