/*
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 { RadialBucketCalculator } from "./RadialBucketCalculator";
import { markType, Point_$type, enumGetBox, typeCast, runOn, markDep } from "igniteui-angular-core";
import { isNaN_, intDivide, isInfinity } from "igniteui-angular-core";
import { RadialBase } from "./RadialBase";
import { CategoryLineRasterizer } from "./CategoryLineRasterizer";
import { DependencyProperty } from "igniteui-angular-core";
import { TrendLineType_$type } from "igniteui-angular-core";
import { Brush } from "igniteui-angular-core";
import { PenLineCap_$type } from "igniteui-angular-core";
import { DoubleCollection } from "igniteui-angular-core";
import { RadialFrame } from "./RadialFrame";
import { ScalerParams } from "./ScalerParams";
import { Rect } from "igniteui-angular-core";
import { DataLegendSeriesValueInfo } from "igniteui-angular-core";
import { DataLegendSeriesContext } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { AxisRange } from "./AxisRange";
import { NumericAxisBase } from "./NumericAxisBase";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { RadialBaseView } from "./RadialBaseView";
import { CollisionAvoider } from "./CollisionAvoider";
import { Clipper } from "igniteui-angular-core";
import { TrendResolutionParams } from "./TrendResolutionParams";
import { RadialTrendLineManager } from "./RadialTrendLineManager";
import { CategoryMarkerManager } from "./CategoryMarkerManager";
import { PropertyMetadata } from "igniteui-angular-core";
import { stringIsNullOrEmpty } from "igniteui-angular-core";
/**
 * @hidden
 */
export let AnchoredRadialBucketCalculator = /*@__PURE__*/ (() => {
    class AnchoredRadialBucketCalculator extends RadialBucketCalculator {
        constructor(a) {
            super(a);
            this.f = null;
            this.f = a;
        }
        getBucket(a) {
            let b = this.f.cw.s8;
            let c = Math.min(a * this.b, b.count - 1);
            let d = Math.min(c + this.b - 1, b.count - 1);
            let e = NaN;
            let f = NaN;
            for (let g = c; g <= d; ++g) {
                let h = b.item(g);
                if (!isNaN_(e)) {
                    if (!isNaN_(h)) {
                        e = Math.min(e, h);
                        f = Math.max(f, h);
                    }
                }
                else {
                    e = h;
                    f = h;
                }
            }
            if (!isNaN_(e)) {
                return [0.5 * (c + d), e, f];
            }
            return [0.5 * (c + d), NaN, NaN];
        }
    }
    AnchoredRadialBucketCalculator.$t = markType(AnchoredRadialBucketCalculator, 'AnchoredRadialBucketCalculator', RadialBucketCalculator.$);
    return AnchoredRadialBucketCalculator;
})();
/**
 * @hidden
 */
export let AnchoredRadialSeries = /*@__PURE__*/ (() => {
    class AnchoredRadialSeries extends RadialBase {
        constructor() {
            super();
            this.s3 = null;
            this.s7 = null;
            this.ua = { $type: Point_$type, x: 0, y: 0 };
            this.s5 = null;
            this.s4 = null;
            this.s5 = new RadialFrame(3);
            this.s3 = new CategoryLineRasterizer();
        }
        bx() {
            return new AnchoredRadialSeriesView(this);
        }
        kx() {
            super.kx();
            this.rp = null;
            this.rw = null;
        }
        hy(a, b) {
            let c = this.js(b);
            if (c == AnchoredRadialSeries.$$p[2]) {
                return this.hz(a, b, this.to);
            }
            return super.hy(a, b);
        }
        l2(a) {
            super.l2(a);
            this.s2 = a;
        }
        hl(a, b) {
            return this.hm(a, b, this.rp, null, this.s8);
        }
        hj(a, b) {
            return this.hk(a, b, this.rp, null, this.s8);
        }
        f5(a, b, c, d, e) {
            if (this.s8 == null) {
                return Number.POSITIVE_INFINITY;
            }
            return this.f6(a, b, this.rp, d, e, this.s8.count, null);
        }
        gl(a, b, c) {
            let d = this.getEffectiveViewport1(this.b0);
            let e = this.td(this.rp, this.b0.bv, this.b0.bu, d);
            let f = new ScalerParams(0, this.b0.bv, this.b0.bu, this.rp.cg, d);
            f.c = this.cd.to;
            return this.gn(this.s8, a, this.rp, f, e, null, b, c);
        }
        pq(a, b, c) {
            if (this.rw == null || this.rp == null || this.b0 == null || this.b0.bv.isEmpty || this.b0.bu.isEmpty) {
                return { $type: Point_$type, x: NaN, y: NaN };
            }
            let d = this.getEffectiveViewport1(this.b0);
            let e = new ScalerParams(0, this.b0.bv, this.b0.bu, this.rw.cg, d);
            e.c = this.getEffectiveViewport1(this.b0);
            let f = this.gl(a, b, c);
            f = this.rw.ei(f, e);
            let g = this.rx.c(a);
            if (!b && this.rp != null) {
                let h = this.hl(a, c);
                let i = this.hj(a, c);
                let j = this.td(this.rp, this.b0.bv, this.b0.bu, d);
                let k = new ScalerParams(0, this.b0.bv, this.b0.bu, this.rp.cg, d);
                k.c = this.cd.to;
                let l = this.f5(a, h, this.rp, k, j);
                let m = this.f5(a, i, this.rp, k, j);
                if (m <= l) {
                    g = this.rp.ei(i, k) + j;
                }
                else {
                    g = this.rp.ei(h, k) + j;
                }
            }
            let n = this.rx.d(g, f, this.b0.bv, this.b0.bu);
            let o = this.rx.e(g, f, this.b0.bv, this.b0.bu);
            return { $type: Point_$type, x: n, y: o };
        }
        get s8() {
            return this.s7;
        }
        set s8(a) {
            if (this.s7 != a) {
                let b = this.s7;
                this.s7 = a;
                this.raisePropertyChanged("ValueColumn", b, this.s7);
            }
        }
        getDataLegendSeriesContextAt(a, b) {
            let c = new DataLegendSeriesValueInfo();
            c.a = 0;
            c.l = this.gl({ $type: Point_$type, x: a, y: b }, false, false);
            c.p = "Value";
            c.q = this.to != null ? this.to : "Value";
            c.r = this.tk != null ? this.tk : "V:";
            c.s = this.tm != null ? this.tm : "";
            let d = new DataLegendSeriesContext();
            d.f = ((() => {
                let $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
                $ret.add(c);
                return $ret;
            })());
            d.b = this.av();
            return d;
        }
        get t6() {
            return this.c(AnchoredRadialSeries.tv);
        }
        set t6(a) {
            this.h(AnchoredRadialSeries.tv, a);
        }
        ap(a) {
            if (a != null && a == this.rp && this.s8 != null && this.s8.count > 0) {
                return new AxisRange(0, this.s8.count - 1);
            }
            if (a != null && a == this.rw && this.s8 != null && this.s8.count > 0) {
                return new AxisRange(this.s8.minimum, this.s8.maximum);
            }
            return null;
        }
        l7(a, b, c, d) {
            super.l7(a, b, c, d);
            if (this.s2.cx.g$b(a, b, c, d)) {
                this.ml(false);
                this.ls();
            }
            let e = typeCast(NumericAxisBase.$, this.rw);
            switch (b) {
                case "FastItemsSource":
                    if (typeCast(IFastItemsSource_$type, c) !== null) {
                        c.deregisterColumn(this.s8);
                        this.s8 = null;
                    }
                    if (typeCast(IFastItemsSource_$type, d) !== null) {
                        this.s8 = this.ch(this.to);
                        this.s2.cs.e(this.fv);
                    }
                    if (e != null && !e.c0()) {
                        this.s2.cs.e(this.fv);
                        this.ml(false);
                    }
                    break;
                case AnchoredRadialSeries.$$p[2]:
                    if (this.ck != null) {
                        this.ck.deregisterColumn(this.s8);
                        this.s8 = this.ch(this.to);
                    }
                    break;
                case "ValueColumn":
                    if (e != null && !e.c0()) {
                        this.s2.cs.e(this.fv);
                        this.ml(false);
                    }
                    break;
                case "TrendLineBrush":
                    this.mz();
                    break;
                case "TrendLineType":
                    this.ls();
                    break;
            }
        }
        k3(a, b, c, d) {
            switch (a) {
                case 4:
                case 1:
                case 0:
                    this.s2.cs.e(this.fv);
                    break;
            }
            this.s2.cx.g$e(a, b, c, d);
            switch (a) {
                case 4:
                    if (this.rw != null && !this.rw.c0()) {
                        this.ml(true);
                    }
                    break;
                case 1:
                    if (this.rw != null && !this.rw.c0()) {
                        this.ml(true);
                    }
                    break;
                case 0:
                    if (this.rw != null && !this.rw.c0()) {
                        this.ml(true);
                    }
                    break;
                case 2:
                    if (this.to != null && this.s2.cs.b > 0 && this.rw != null && !this.rw.c0()) {
                        this.ml(true);
                    }
                    break;
                case 3:
                    if (d == this.to) {
                        if (this.rw != null && !this.rw.c0()) {
                            this.ml(true);
                        }
                    }
                    break;
            }
        }
        fb(a, b, c) {
            let d = super.fb(a, b, c);
            let e = c;
            if (this.ck == null || this.ck.count == 0 || this.rp == null || this.s8 == null || this.rp.le == 0 || this.rw == null || isInfinity(this.rw.lv) || isInfinity(this.rw.lu) || e.cs.b < 1) {
                d = false;
            }
            return d;
        }
        getOffsetValue() {
            return this.td(this.rp, this.b0.bv, this.b0.bu, this.getEffectiveViewport1(this.b0));
        }
        getCategoryWidth() {
            return this.rp.getCategorySize(this.b0.bv, this.b0.bu, this.getEffectiveViewport1(this.b0));
        }
        get_tb() {
            return false;
        }
        get tb() {
            return this.get_tb();
        }
        get_c6() {
            return true;
        }
        get_ek() {
            return this.rw != null && this.rw.cg;
        }
        td(a, b, c, d) {
            let e = 0;
            let f = this.preferredCategoryMode(a);
            if (f == 0 && a.categoryMode != 0) {
                f = 1;
            }
            switch (f) {
                case 0:
                    e = 0;
                    break;
                case 1:
                    e = 0.5 * a.getCategorySize(b, c, d);
                    break;
                case 2:
                    e = a.getGroupCenter(this.sj(), b, c, d);
                    break;
            }
            if (a.cg) {
                e = -e;
            }
            return e;
        }
        sr(a, b) {
            let c = b.bv;
            let d = b.bu;
            let e = this.getEffectiveViewport1(b);
            let f = this.rp;
            let g = this.rw;
            let h = g.lv;
            let i = g.lu;
            a.f.clear();
            a.m.clear();
            a.p.clear();
            let j = this.qj();
            let k = 0;
            let l = b;
            let m = new CollisionAvoider();
            let n = 0;
            let o = b.cs.d;
            n = this.td(f, c, d, e);
            l.cx.i = this.rw.nm;
            l.cx.h = this.rw.nl;
            l.cx.j = (p, q) => this.te(p, q, c, d);
            l.cx.k = (p, q) => this.tf(p, q, c, d);
            let p = ((() => {
                let $ret = new Clipper(0, d, false);
                $ret.i = a.p;
                return $ret;
            })());
            let q = ((() => {
                let $ret = new TrendResolutionParams();
                $ret.c = b.cs.b;
                $ret.d = b.cs.c;
                $ret.e = o;
                $ret.a = n;
                $ret.b = this.fv;
                $ret.f = d;
                $ret.g = c;
                return $ret;
            })());
            l.cx.l(a.p, this.s6, this.s8, this.th, (r) => this.rp.getScaledAngle(r), (r) => this.rw.ns(r), q, p);
            let r = true;
            if (this.tc(b)) {
                o--;
            }
            for (let s = b.cs.c; s <= o; ++s) {
                let t = s;
                if (t * b.cs.b >= this.rp.le) {
                    t -= intDivide((this.rp.le), b.cs.b);
                }
                let u = b.cs.getBucket(t);
                if (!isNaN_(u[0])) {
                    u[0] = f.getScaledAngle(u[0]) + n;
                    if (u[1] < h || u[1] > i) {
                        continue;
                    }
                    u[1] = g.ns(u[1]);
                    if (b.cs.b > 1) {
                        if (u[2] < h || u[2] > i) {
                            continue;
                        }
                        u[2] = g.ns(u[2]);
                    }
                    else {
                        u[2] = u[1];
                    }
                    if ((isNaN_(u[1]) || isNaN_(u[2])) && r && this.tb && this.ta()) {
                        o++;
                    }
                    else {
                        r = false;
                    }
                    a.f.add(u);
                    if (j) {
                        let v = Math.min(t * b.cs.b, this.ck.count - 1);
                        let w = this.rx.d(u[0], u[1], c, d);
                        let x = this.rx.e(u[0], u[1], c, d);
                        let y = new Rect(0, w - 5, x - 5, 11, 11);
                        if (!isNaN_(w) && !isNaN_(x) && !isInfinity(w) && !isInfinity(x) && m.tryAdd(y)) {
                            a.m.add({ $type: Point_$type, x: w, y: x });
                            let z = b.ct.item(k);
                            z.al = t;
                            z.ak = v;
                            z.content.item = this.ck.item(v);
                            ++k;
                        }
                    }
                }
                else {
                    if (r && this.tb && this.ta()) {
                        o++;
                    }
                }
            }
            b.ct.count = k;
            return;
        }
        te(a, b, c, d) {
            return this.rx.d(a, b, c, d);
        }
        tf(a, b, c, d) {
            return this.rx.e(a, b, c, d);
        }
        tc(a) {
            let b = a;
            return !this.tb && b.cs.c == 0 && b.cs.d == this.rp.le;
        }
        s1(a, b, c) {
            let d = null;
            let e = c.bv;
            let f = c.bu;
            if (b > -1 && !e.isEmpty && !f.isEmpty) {
                let g = a._inner[0][0] < f.left - 2000 ? f.left - 10 : NaN;
                let h = f.bottom + 10;
                let i = a._inner[b][0] > f.right + 2000 ? f.right + 10 : NaN;
                let j = f.top - 10;
                d = new Clipper(1, g, h, i, j, false);
            }
            return d;
        }
        tu(a, b, c, d, e) {
            if (a.count > 0 && d.count > 0) {
                if (!e || this.s9()) {
                    a.add(this.ua);
                    a.add(a._inner[0]);
                    d.add(this.ua);
                    d.add(d._inner[0]);
                }
            }
        }
        ta() {
            return !this.s9();
        }
        s9() {
            let a = this.b0.bv;
            return !a.containsPoint({ $type: Point_$type, x: 0.5, y: 0.5 });
        }
        k0(a, b) {
            super.k0(a, b);
            let c = b;
            if (a) {
                c.ct.clear();
            }
            c.cx.g$d();
        }
        su(a, b) {
            let c = b.bv;
            let d = b.bu;
            let e = this.getEffectiveViewport1(b);
            let f = this.pv(b);
            let g = b;
            g.cx.g$g(a.p);
            CategoryMarkerManager.e(this, a.m, g.ct, this.ql);
            this.tr(b, a);
            g.cm();
            this.tq(d, c, e, f, g);
        }
        s0(a, b, c) {
            if (b < a || a < 0 || a > this.s8.count || b < 0 || b > this.s8.count || c == null) {
                return null;
            }
            let d = new Array((b - a) + 1);
            let e = c.cm;
            let f = null;
            if (e) {
                f = c.i$b;
            }
            for (let g = a; g <= b; g++) {
                let h = g;
                if (e) {
                    h = f._inner[h];
                }
                d[g - a] = this.ck.item(g);
            }
            return d;
        }
        ts(a, b, c, d, e, f) {
            let g = this.bk != 1;
            this.r3.a1(this.r3.d, d.cm, a, b, c, d, e, f, true);
            this.r3.aa(this.ft);
            let h = this.r3.av;
            let i = null;
            let j = this.ck;
            let k = null;
            if (g && this.cd != null) {
                i = this.cd.a7.getHighlightingInfo(this, j, h.o, h.n, true);
                if (this.cd.a7.isCrossSeriesHighlight(this)) {
                    k = this.cd.a7.getHighlightingInfo(this, j, h.o, h.n, true);
                }
                h.b = i;
            }
            h.f = f;
            this.ss(h);
            this.r3.y(this, i, f, g, h.m, this.cd.a7.totalHighlightingProgress);
        }
        tt(a, b, c, d, e, f) {
            let g = this.bk != 1;
            this.r3.a1(this.r3.b, d.cm, a, b, c, d, e, f, false);
            this.r3.ab(this.ft);
            let h = this.r3.aw;
            let i = null;
            let j = this.ck;
            if (g && this.cd != null) {
                i = this.cd.a7.getHighlightingInfo(this, j, h.o, h.n, false);
                h.b = i;
            }
            h.f = f;
            this.st(h);
            this.r3.z(this, i, f, g, b < 0);
        }
        tr(a, b) {
            a.b3 = true;
            this.r3.az(this, this.se(), runOn(this, this.rm), this.sh(a), this.si(a));
            let c = this.r3.d;
            let d = c != null;
            let e = this.rp;
            if (e == null) {
                return;
            }
            let f = this.getEffectiveViewport1(a);
            let g = new ScalerParams(0, a.bv, a.bu, e.cg, f);
            let h = this.ck == null ? 0 : this.ck.count;
            let i = a;
            let j = b.f;
            let k = i.cs.c;
            let l = i.cs.d;
            let m = i.cs.b;
            let n = k * m;
            for (let o = 0; o < a.ct.count; o++) {
                let p = a.ct.item(o);
                let q = p.content;
                if (d) {
                    let r = p.al;
                    this.ts(j, r, h, e, g, a.q);
                }
                this.r3.ac(p, q);
            }
        }
        tq(a, b, c, d, e) {
            e.cy(a, b, c, d);
        }
        mz() {
            super.mz();
            if (this.index < 0) {
                return;
            }
            this.s2.cz();
        }
        h1(a, b) {
            if (a == this.s2.cx.g$j) {
                return null;
            }
            return super.h1(a, b);
        }
        eo(a) {
            let b = this.b0.bv;
            b = b.copy();
            let c = this.b0.bu;
            let d = !b.isEmpty && !c.isEmpty && this.ck != null ? this.ck.indexOf(a) : -1;
            if (this.rp == null || this.s8 == null || this.rw == null) {
                return false;
            }
            if (d < 0 || d > this.s8.count - 1) {
                return false;
            }
            let e = this.rp.getScaledAngle(d);
            let f = this.rw.ns(this.s8.item(d));
            if (isNaN_(f)) {
                f = (this.rw.nl + this.rw.nm) / 2;
            }
            let g = 0.5 + (Math.cos(e) * f);
            let h = 0.5 + (Math.sin(e) * f);
            if (!isNaN_(g)) {
                if (g < b.left + 0.1 * b.width) {
                    g = g + 0.4 * b.width;
                    b.x = g - 0.5 * b.width;
                }
                if (g > b.right - 0.1 * b.width) {
                    g = g - 0.4 * b.width;
                    b.x = g - 0.5 * b.width;
                }
            }
            if (!isNaN_(h)) {
                if (h < b.top + 0.1 * b.height) {
                    h = h + 0.4 * b.height;
                    b.y = h - 0.5 * b.height;
                }
                if (h > b.bottom - 0.1 * b.height) {
                    h = h - 0.4 * b.height;
                    b.y = h - 0.5 * b.height;
                }
            }
            if (this.b8 != null) {
                this.b8.au(this.cd, b, true);
            }
            return d >= 0;
        }
        mn(a, b) {
            super.mn(a, b);
            if (!this.e1) {
                this.b0.a2(b);
                return;
            }
            this.b0.a2(b);
            let c = typeCast(AnchoredRadialSeriesView.$, this.bz);
            c.cs.e(this.fv);
            if (this.cx(this.bz)) {
                return;
            }
            if (!this.ev) {
                this.s5 = new RadialFrame(3);
                this.sr(this.s5, c);
            }
            this.ev = false;
            this.su(this.s5, c);
            this.e1 = false;
        }
        mk(a, b, c, d, e) {
            super.mk(a, b, c, d, e);
            let f = this.a6.a$h.item(d);
            let g = f;
            g.cs.e(this.fv);
            f.a1(c);
            if (this.cx(g)) {
                return;
            }
            if (this.s4 == null) {
                this.s4 = new RadialFrame(3);
            }
            this.s4.u();
            this.sr(this.s4, g);
            this.su(this.s4, g);
        }
        la(a) {
            super.la(a);
            this.a8.exportTrendlineData(this, a, this.s2.cx.g$j);
        }
    }
    AnchoredRadialSeries.$t = markType(AnchoredRadialSeries, 'AnchoredRadialSeries', RadialBase.$);
    AnchoredRadialSeries.tv = DependencyProperty.i("ActualTrendLineBrush", Brush.$, AnchoredRadialSeries.$, new PropertyMetadata(2, null, (a, b) => a.raisePropertyChanged("ActualTrendLineBrush", b.oldValue, b.newValue)));
    AnchoredRadialSeries.$$p = markDep(DependencyProperty, PropertyMetadata, AnchoredRadialSeries, 'raisePropertyChanged', ['ValueMemberAsLegendLabel:tk:t3', [2, null], 'ValueMemberAsLegendUnit:tm:t4', [2, null], 'ValueMemberPath:to:t5', [2, null], 'TrendLineType:s6:t1', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness:tg:t0', [1, 1.5], 'TrendLinePeriod:th:tz', [1, 7], 'TrendLineZIndex:ti:t2', [1, 1], 'TrendLineBrush:t7:tw', [Brush.$, null], 'TrendLineDashArray:t8:tx', [DoubleCollection.$], 'TrendLineDashCap:t9:ty', [PenLineCap_$type, enumGetBox(PenLineCap_$type, 0)]]);
    return AnchoredRadialSeries;
})();
/**
 * @hidden
 */
export let AnchoredRadialSeriesView = /*@__PURE__*/ (() => {
    class AnchoredRadialSeriesView extends RadialBaseView {
        constructor(a) {
            super(a);
            this.cw = null;
            this.cx = null;
            this.cs = new AnchoredRadialBucketCalculator(this);
            this.cw = a;
            this.cx = new RadialTrendLineManager();
        }
        cy(a, b, c, d) {
        }
        cz() {
            this.cw.t6 = null;
            if (this.cw.t7 != null) {
                this.cw.t6 = this.cw.t7;
            }
            else {
                this.cw.t6 = this.cw.o3;
            }
        }
        a5(a, b) {
            if (a.d) {
                if (!b) {
                }
                if (this.cw.s6 != 0 && !b) {
                    let c = this.cx.g$j;
                    c.ac = this.cw.tg;
                    c._stroke = this.cw.t6;
                    c.ai = this.cw.t8;
                    c.ad = this.cw.t9;
                    a.v(c);
                }
            }
            super.a5(a, b);
        }
        getDefaultTooltipTemplate() {
            let a = "<div class='ui-chart-default-tooltip-content'>";
            if (this.cw.rp.fz != null) {
                a += "<span>${item." + this.cw.rp.fz + "}</span><br/>";
            }
            a += "<span";
            let b = this.e.a6.a$r(this.e);
            if (!stringIsNullOrEmpty(b)) {
                a += " style='color:" + b + "'";
            }
            a += ">" + this.cw.title + ": </span><span class='ui-priority-primary'>" + "${item." + this.cw.to + "}</span></div>";
            return a;
        }
    }
    AnchoredRadialSeriesView.$t = markType(AnchoredRadialSeriesView, 'AnchoredRadialSeriesView', RadialBaseView.$);
    return AnchoredRadialSeriesView;
})();
