/*
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-react-core";
import { isNaN_, intDivide, isInfinity } from "igniteui-react-core";
import { RadialBase } from "./RadialBase";
import { CategoryLineRasterizer } from "./CategoryLineRasterizer";
import { DependencyProperty } from "igniteui-react-core";
import { TrendLineType_$type } from "igniteui-react-core";
import { Brush } from "igniteui-react-core";
import { PenLineCap_$type } from "igniteui-react-core";
import { DoubleCollection } from "igniteui-react-core";
import { RadialFrame } from "./RadialFrame";
import { ScalerParams } from "./ScalerParams";
import { Rect } from "igniteui-react-core";
import { AxisRange } from "./AxisRange";
import { NumericAxisBase } from "./NumericAxisBase";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { RadialBaseView } from "./RadialBaseView";
import { CollisionAvoider } from "./CollisionAvoider";
import { Clipper } from "igniteui-react-core";
import { TrendResolutionParams } from "./TrendResolutionParams";
import { RadialTrendLineManager } from "./RadialTrendLineManager";
import { CategoryMarkerManager } from "./CategoryMarkerManager";
import { PropertyMetadata } from "igniteui-react-core";
import { stringIsNullOrEmpty } from "igniteui-react-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.q9;
            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 = /*@__PURE__*/ markType(AnchoredRadialBucketCalculator, 'AnchoredRadialBucketCalculator', RadialBucketCalculator.$);
    return AnchoredRadialBucketCalculator;
})();
/**
 * @hidden
 */
export let AnchoredRadialSeries = /*@__PURE__*/ (() => {
    class AnchoredRadialSeries extends RadialBase {
        constructor() {
            super();
            this.q4 = null;
            this.q8 = null;
            this.r5 = { $type: Point_$type, x: 0, y: 0 };
            this.q6 = null;
            this.q5 = null;
            this.q6 = new RadialFrame(3);
            this.q4 = new CategoryLineRasterizer();
        }
        bp() {
            return new AnchoredRadialSeriesView(this);
        }
        ji() {
            super.ji();
            this.pr = null;
            this.py = null;
        }
        gt(a, b) {
            let c = this.ic(b);
            if (c == AnchoredRadialSeries.$$p[0]) {
                return this.gu(a, b, this.rl);
            }
            return super.gt(a, b);
        }
        kk(a) {
            super.kk(a);
            this.q3 = a;
        }
        gf(a, b) {
            return this.gg(a, b, this.pr, null, this.q9);
        }
        gd(a, b) {
            return this.ge(a, b, this.pr, null, this.q9);
        }
        e2(a, b, c, d, e) {
            if (this.q9 == null) {
                return Number.POSITIVE_INFINITY;
            }
            return this.e3(a, b, this.pr, d, e, this.q9.count, null);
        }
        fh(a, b, c) {
            let d = this.getEffectiveViewport1(this.bs);
            let e = this.re(this.pr, this.bs.bv, this.bs.bu, d);
            let f = new ScalerParams(0, this.bs.bv, this.bs.bu, this.pr.ca, d);
            f.c = this.b6.o7;
            return this.fj(this.q9, a, this.pr, f, e, null, b, c);
        }
        nt(a, b, c) {
            if (this.py == null || this.pr == null || this.bs == null || this.bs.bv.isEmpty || this.bs.bu.isEmpty) {
                return { $type: Point_$type, x: NaN, y: NaN };
            }
            let d = this.getEffectiveViewport1(this.bs);
            let e = new ScalerParams(0, this.bs.bv, this.bs.bu, this.py.ca, d);
            e.c = this.getEffectiveViewport1(this.bs);
            let f = this.fh(a, b, c);
            f = this.py.dz(f, e);
            let g = this.pz.c(a);
            if (!b && this.pr != null) {
                let h = this.gf(a, c);
                let i = this.gd(a, c);
                let j = this.re(this.pr, this.bs.bv, this.bs.bu, d);
                let k = new ScalerParams(0, this.bs.bv, this.bs.bu, this.pr.ca, d);
                k.c = this.b6.o7;
                let l = this.e2(a, h, this.pr, k, j);
                let m = this.e2(a, i, this.pr, k, j);
                if (m <= l) {
                    g = this.pr.dz(i, k) + j;
                }
                else {
                    g = this.pr.dz(h, k) + j;
                }
            }
            let n = this.pz.d(g, f, this.bs.bv, this.bs.bu);
            let o = this.pz.e(g, f, this.bs.bv, this.bs.bu);
            return { $type: Point_$type, x: n, y: o };
        }
        get q9() {
            return this.q8;
        }
        set q9(a) {
            if (this.q8 != a) {
                let b = this.q8;
                this.q8 = a;
                this.raisePropertyChanged("ValueColumn", b, this.q8);
            }
        }
        get r1() {
            return this.c(AnchoredRadialSeries.rs);
        }
        set r1(a) {
            this.h(AnchoredRadialSeries.rs, a);
        }
        ao(a) {
            if (a != null && a == this.pr && this.q9 != null && this.q9.count > 0) {
                return new AxisRange(0, this.q9.count - 1);
            }
            if (a != null && a == this.py && this.q9 != null && this.q9.count > 0) {
                return new AxisRange(this.q9.minimum, this.q9.maximum);
            }
            return null;
        }
        kp(a, b, c, d) {
            super.kp(a, b, c, d);
            if (this.q3.cx.g$b(a, b, c, d)) {
                this.k3(false);
                this.ka();
            }
            let e = typeCast(NumericAxisBase.$, this.py);
            switch (b) {
                case "FastItemsSource":
                    if (typeCast(IFastItemsSource_$type, c) !== null) {
                        c.deregisterColumn(this.q9);
                        this.q9 = null;
                    }
                    if (typeCast(IFastItemsSource_$type, d) !== null) {
                        this.q9 = this.ca(this.rl);
                        this.q3.cs.e(this.fq);
                    }
                    if (e != null && !e.cn()) {
                        this.q3.cs.e(this.fq);
                        this.k3(false);
                    }
                    break;
                case AnchoredRadialSeries.$$p[0]:
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.q9);
                        this.q9 = this.ca(this.rl);
                    }
                    break;
                case "ValueColumn":
                    if (e != null && !e.cn()) {
                        this.q3.cs.e(this.fq);
                        this.k3(false);
                    }
                    break;
                case "TrendLineBrush":
                    this.lg();
                    break;
                case "TrendLineType":
                    this.ka();
                    break;
            }
        }
        jo(a, b, c, d) {
            switch (a) {
                case 4:
                case 1:
                case 0:
                    this.q3.cs.e(this.fq);
                    break;
            }
            this.q3.cx.g$e(a, b, c, d);
            switch (a) {
                case 4:
                    if (this.py != null && !this.py.cn()) {
                        this.k3(true);
                    }
                    break;
                case 1:
                    if (this.py != null && !this.py.cn()) {
                        this.k3(true);
                    }
                    break;
                case 0:
                    if (this.py != null && !this.py.cn()) {
                        this.k3(true);
                    }
                    break;
                case 2:
                    if (this.rl != null && this.q3.cs.b > 0 && this.py != null && !this.py.cn()) {
                        this.k3(true);
                    }
                    break;
                case 3:
                    if (d == this.rl) {
                        if (this.py != null && !this.py.cn()) {
                            this.k3(true);
                        }
                    }
                    break;
            }
        }
        ec(a, b, c) {
            let d = super.ec(a, b, c);
            let e = c;
            if (this.cd == null || this.cd.count == 0 || this.pr == null || this.q9 == null || this.pr.j8 == 0 || this.py == null || isInfinity(this.py.kd) || isInfinity(this.py.kc) || e.cs.b < 1) {
                d = false;
            }
            return d;
        }
        getOffsetValue() {
            return this.re(this.pr, this.bs.bv, this.bs.bu, this.getEffectiveViewport1(this.bs));
        }
        getCategoryWidth() {
            return this.pr.getCategorySize(this.bs.bv, this.bs.bu, this.getEffectiveViewport1(this.bs));
        }
        get_rc() {
            return false;
        }
        get rc() {
            return this.get_rc();
        }
        re(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.qk(), b, c, d);
                    break;
            }
            if (a.ca) {
                e = -e;
            }
            return e;
        }
        qs(a, b) {
            let c = b.bv;
            let d = b.bu;
            let e = this.getEffectiveViewport1(b);
            let f = this.pr;
            let g = this.py;
            let h = g.kd;
            let i = g.kc;
            a.f.clear();
            a.m.clear();
            a.p.clear();
            let j = this.ok();
            let k = 0;
            let l = b;
            let m = new CollisionAvoider();
            let n = 0;
            let o = b.cs.d;
            n = this.re(f, c, d, e);
            l.cx.i = this.py.ls;
            l.cx.h = this.py.lr;
            l.cx.j = (p, q) => this.rf(p, q, c, d);
            l.cx.k = (p, q) => this.rg(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.fq;
                $ret.f = d;
                $ret.g = c;
                return $ret;
            })());
            l.cx.l(a.p, this.q7, this.q9, this.ri, (r) => this.pr.getScaledAngle(r), (r) => this.py.ly(r), q, p);
            let r = true;
            if (this.rd(b)) {
                o--;
            }
            for (let s = b.cs.c; s <= o; ++s) {
                let t = s;
                if (t * b.cs.b >= this.pr.j8) {
                    t -= intDivide((this.pr.j8), 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.ly(u[1]);
                    if (b.cs.b > 1) {
                        if (u[2] < h || u[2] > i) {
                            continue;
                        }
                        u[2] = g.ly(u[2]);
                    }
                    else {
                        u[2] = u[1];
                    }
                    if ((isNaN_(u[1]) || isNaN_(u[2])) && r && this.rc && this.rb()) {
                        o++;
                    }
                    else {
                        r = false;
                    }
                    a.f.add(u);
                    if (j) {
                        let v = Math.min(t * b.cs.b, this.cd.count - 1);
                        let w = this.pz.d(u[0], u[1], c, d);
                        let x = this.pz.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.cd.item(v);
                            ++k;
                        }
                    }
                }
                else {
                    if (r && this.rc && this.rb()) {
                        o++;
                    }
                }
            }
            b.ct.count = k;
            return;
        }
        rf(a, b, c, d) {
            return this.pz.d(a, b, c, d);
        }
        rg(a, b, c, d) {
            return this.pz.e(a, b, c, d);
        }
        rd(a) {
            let b = a;
            return !this.rc && b.cs.c == 0 && b.cs.d == this.pr.j8;
        }
        q2(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;
        }
        rr(a, b, c, d, e) {
            if (a.count > 0 && d.count > 0) {
                if (!e || this.ra()) {
                    a.add(this.r5);
                    a.add(a._inner[0]);
                    d.add(this.r5);
                    d.add(d._inner[0]);
                }
            }
        }
        rb() {
            return !this.ra();
        }
        ra() {
            let a = this.bs.bv;
            return !a.containsPoint({ $type: Point_$type, x: 0.5, y: 0.5 });
        }
        jl(a, b) {
            super.jl(a, b);
            let c = b;
            if (a) {
                c.ct.clear();
            }
            c.cx.g$d();
        }
        qv(a, b) {
            let c = b.bv;
            let d = b.bu;
            let e = this.getEffectiveViewport1(b);
            let f = this.ny(b);
            let g = b;
            g.cx.g$g(a.p);
            CategoryMarkerManager.e(this, a.m, g.ct, this.om);
            this.ro(b, a);
            g.cm();
            this.rn(d, c, e, f, g);
        }
        q1(a, b, c) {
            if (b < a || a < 0 || a > this.q9.count || b < 0 || b > this.q9.count || c == null) {
                return null;
            }
            let d = new Array((b - a) + 1);
            let e = c.cf;
            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.cd.item(g);
            }
            return d;
        }
        rp(a, b, c, d, e, f) {
            let g = this.be != 1;
            this.p4.a1(this.p4.d, d.cf, a, b, c, d, e, f, true);
            this.p4.aa(this.es);
            let h = this.p4.av;
            let i = null;
            let j = this.cd;
            let k = null;
            if (g && this.b6 != null) {
                i = this.b6.az.getHighlightingInfo(this, j, h.o, h.n, true);
                if (this.b6.az.isCrossSeriesHighlight(this)) {
                    k = this.b6.az.getHighlightingInfo(this, j, h.o, h.n, true);
                }
                h.b = i;
            }
            h.f = f;
            this.qt(h);
            this.p4.y(this, i, f, g, h.m, this.b6.az.totalHighlightingProgress);
        }
        rq(a, b, c, d, e, f) {
            let g = this.be != 1;
            this.p4.a1(this.p4.b, d.cf, a, b, c, d, e, f, false);
            this.p4.ab(this.es);
            let h = this.p4.aw;
            let i = null;
            let j = this.cd;
            if (g && this.b6 != null) {
                i = this.b6.az.getHighlightingInfo(this, j, h.o, h.n, false);
                h.b = i;
            }
            h.f = f;
            this.qu(h);
            this.p4.z(this, i, f, g, b < 0);
        }
        ro(a, b) {
            a.b3 = true;
            this.p4.az(this, this.qf(), runOn(this, this.po), this.qi(a), this.qj(a));
            let c = this.p4.d;
            let d = c != null;
            let e = this.pr;
            if (e == null) {
                return;
            }
            let f = this.getEffectiveViewport1(a);
            let g = new ScalerParams(0, a.bv, a.bu, e.ca, f);
            let h = this.cd == null ? 0 : this.cd.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.rp(j, r, h, e, g, a.q);
                }
                this.p4.ac(p, q);
            }
        }
        rn(a, b, c, d, e) {
            e.cy(a, b, c, d);
        }
        lg() {
            super.lg();
            if (this.gi < 0) {
                return;
            }
            this.q3.cz();
        }
        gw(a, b) {
            if (a == this.q3.cx.g$j) {
                return null;
            }
            return super.gw(a, b);
        }
        dq(a) {
            let b = this.bs.bv;
            b = b.copy();
            let c = this.bs.bu;
            let d = !b.isEmpty && !c.isEmpty && this.cd != null ? this.cd.indexOf(a) : -1;
            if (this.pr == null || this.q9 == null || this.py == null) {
                return false;
            }
            if (d < 0 || d > this.q9.count - 1) {
                return false;
            }
            let e = this.pr.getScaledAngle(d);
            let f = this.py.ly(this.q9.item(d));
            if (isNaN_(f)) {
                f = (this.py.lr + this.py.ls) / 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.b1 != null) {
                this.b1.ap(this.b6, b, true);
            }
            return d >= 0;
        }
        k5(a, b) {
            super.k5(a, b);
            if (!this.d2) {
                this.bs.a2(b);
                return;
            }
            this.bs.a2(b);
            let c = typeCast(AnchoredRadialSeriesView.$, this.br);
            c.cs.e(this.fq);
            if (this.cp(this.br)) {
                return;
            }
            if (!this.dw) {
                this.q6 = new RadialFrame(3);
                this.qs(this.q6, c);
            }
            this.dw = false;
            this.qv(this.q6, c);
            this.d2 = false;
        }
        k2(a, b, c, d, e) {
            super.k2(a, b, c, d, e);
            let f = this.a3.a$h.item(d);
            let g = f;
            g.cs.e(this.fq);
            f.a1(c);
            if (this.cp(g)) {
                return;
            }
            if (this.q5 == null) {
                this.q5 = new RadialFrame(3);
            }
            this.q5.u();
            this.qs(this.q5, g);
            this.qv(this.q5, g);
        }
        jv(a) {
            super.jv(a);
            this.a5.exportTrendlineData(this, a, this.q3.cx.g$j);
        }
    }
    AnchoredRadialSeries.$t = /*@__PURE__*/ markType(AnchoredRadialSeries, 'AnchoredRadialSeries', RadialBase.$);
    AnchoredRadialSeries.rs = /*@__PURE__*/ DependencyProperty.i("ActualTrendLineBrush", Brush.$, AnchoredRadialSeries.$, /*@__PURE__*/ new PropertyMetadata(2, null, (a, b) => a.raisePropertyChanged("ActualTrendLineBrush", b.oldValue, b.newValue)));
    AnchoredRadialSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, AnchoredRadialSeries, 'raisePropertyChanged', ['ValueMemberPath:rl:r0', [2, null], 'TrendLineType:q7:ry', [TrendLineType_$type, /*@__PURE__*/ enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness:rh:rx', [1, 1.5], 'TrendLinePeriod:ri:rw', [1, 7], 'TrendLineZIndex:rj:rz', [1, 1], 'TrendLineBrush:r2:rt', [Brush.$, null], 'TrendLineDashArray:r3:ru', [DoubleCollection.$], 'TrendLineDashCap:r4:rv', [PenLineCap_$type, /*@__PURE__*/ 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.r1 = null;
            if (this.cw.r2 != null) {
                this.cw.r1 = this.cw.r2;
            }
            else {
                this.cw.r1 = this.cw.m9;
            }
        }
        a5(a, b) {
            if (a.d) {
                if (!b) {
                }
                if (this.cw.q7 != 0 && !b) {
                    let c = this.cx.g$j;
                    c.ac = this.cw.rh;
                    c._stroke = this.cw.r1;
                    c.ai = this.cw.r3;
                    c.ad = this.cw.r4;
                    a.u(c);
                }
            }
            super.a5(a, b);
        }
        getDefaultTooltipTemplate() {
            let a = "<div class='ui-chart-default-tooltip-content'>";
            if (this.cw.pr.fa != null) {
                a += "<span>${item." + this.cw.pr.fa + "}</span><br/>";
            }
            a += "<span";
            let b = this.e.a3.a$r(this.e);
            if (!stringIsNullOrEmpty(b)) {
                a += " style='color:" + b + "'";
            }
            a += ">" + this.cw.gy + ": </span><span class='ui-priority-primary'>" + "${item." + this.cw.rl + "}</span></div>";
            return a;
        }
    }
    AnchoredRadialSeriesView.$t = /*@__PURE__*/ markType(AnchoredRadialSeriesView, 'AnchoredRadialSeriesView', RadialBaseView.$);
    return AnchoredRadialSeriesView;
})();
//# sourceMappingURL=AnchoredRadialBucketCalculator_combined.js.map
