/*
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, 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.cs.n8;
            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.n3 = null;
            this.n7 = null;
            this.o1 = { $type: Point_$type, x: 0, y: 0 };
            this.n5 = null;
            this.n4 = null;
            this.n5 = new RadialFrame(3);
            this.n3 = new CategoryLineRasterizer();
        }
        bf() {
            return new AnchoredRadialSeriesView(this);
        }
        h1() {
            super.h1();
            this.nd = null;
            this.nf = null;
        }
        fs(a, b) {
            let c = this.g2(b);
            if (c == AnchoredRadialSeries.$$p[0]) {
                return this.ft(a, b, this.ok);
            }
            return super.fs(a, b);
        }
        i2(a) {
            super.i2(a);
            this.n2 = a;
        }
        fe(a, b) {
            return this.ff(a, b, this.nd, null, this.n8);
        }
        fc(a, b) {
            return this.fd(a, b, this.nd, null, this.n8);
        }
        d9(a, b, c, d, e) {
            if (this.n8 == null) {
                return Number.POSITIVE_INFINITY;
            }
            return this.ea(a, b, this.nd, d, e, this.n8.count, null);
        }
        en(a, b, c) {
            let d = this.getEffectiveViewport1(this.bi);
            let e = this.od(this.nd, this.bi.bs, this.bi.br, d);
            let f = new ScalerParams(0, this.bi.bs, this.bi.br, this.nd.ca, d);
            f.c = this.bs.oh;
            return this.ep(this.n8, a, this.nd, f, e, null, b, c);
        }
        lv(a, b, c) {
            if (this.nf == null || this.nd == null || this.bi == null || this.bi.bs.isEmpty || this.bi.br.isEmpty) {
                return { $type: Point_$type, x: NaN, y: NaN };
            }
            let d = this.getEffectiveViewport1(this.bi);
            let e = new ScalerParams(0, this.bi.bs, this.bi.br, this.nf.ca, d);
            e.c = this.getEffectiveViewport1(this.bi);
            let f = this.en(a, b, c);
            f = this.nf.dy(f, e);
            let g = this.ng.c(a);
            if (!b && this.nd != null) {
                let h = this.fe(a, c);
                let i = this.fc(a, c);
                let j = this.od(this.nd, this.bi.bs, this.bi.br, d);
                let k = new ScalerParams(0, this.bi.bs, this.bi.br, this.nd.ca, d);
                k.c = this.bs.oh;
                let l = this.d9(a, h, this.nd, k, j);
                let m = this.d9(a, i, this.nd, k, j);
                if (m <= l) {
                    g = this.nd.dy(i, k) + j;
                }
                else {
                    g = this.nd.dy(h, k) + j;
                }
            }
            let n = this.ng.d(g, f, this.bi.bs, this.bi.br);
            let o = this.ng.e(g, f, this.bi.bs, this.bi.br);
            return { $type: Point_$type, x: n, y: o };
        }
        get n8() {
            return this.n7;
        }
        set n8(a) {
            if (this.n7 != a) {
                let b = this.n7;
                this.n7 = a;
                this.raisePropertyChanged("ValueColumn", b, this.n7);
            }
        }
        get ox() {
            return this.c(AnchoredRadialSeries.oo);
        }
        set ox(a) {
            this.h(AnchoredRadialSeries.oo, a);
        }
        an(a) {
            if (a != null && a == this.nd && this.n8 != null && this.n8.count > 0) {
                return new AxisRange(0, this.n8.count - 1);
            }
            if (a != null && a == this.nf && this.n8 != null && this.n8.count > 0) {
                return new AxisRange(this.n8.minimum, this.n8.maximum);
            }
            return null;
        }
        i7(a, b, c, d) {
            super.i7(a, b, c, d);
            if (this.n2.ct.g$b(a, b, c, d)) {
                this.jl(false);
                this.it();
            }
            let e = typeCast(NumericAxisBase.$, this.nf);
            switch (b) {
                case "FastItemsSource":
                    if (typeCast(IFastItemsSource_$type, c) !== null) {
                        c.deregisterColumn(this.n8);
                        this.n8 = null;
                    }
                    if (typeCast(IFastItemsSource_$type, d) !== null) {
                        this.n8 = this.bw(this.ok);
                        this.n2.co.e(this.eu);
                    }
                    if (e != null && !e.cn()) {
                        this.n2.co.e(this.eu);
                        this.jl(false);
                    }
                    break;
                case AnchoredRadialSeries.$$p[0]:
                    if (this.bz != null) {
                        this.bz.deregisterColumn(this.n8);
                        this.n8 = this.bw(this.ok);
                    }
                    break;
                case "ValueColumn":
                    if (e != null && !e.cn()) {
                        this.n2.co.e(this.eu);
                        this.jl(false);
                    }
                    break;
                case "TrendLineBrush":
                    this.jw();
                    break;
                case "TrendLineType":
                    this.it();
                    break;
            }
        }
        h6(a, b, c, d) {
            switch (a) {
                case 4:
                case 1:
                case 0:
                    this.n2.co.e(this.eu);
                    break;
            }
            this.n2.ct.g$e(a, b, c, d);
            switch (a) {
                case 4:
                    if (this.nf != null && !this.nf.cn()) {
                        this.jl(true);
                    }
                    break;
                case 1:
                    if (this.nf != null && !this.nf.cn()) {
                        this.jl(true);
                    }
                    break;
                case 0:
                    if (this.nf != null && !this.nf.cn()) {
                        this.jl(true);
                    }
                    break;
                case 2:
                    if (this.ok != null && this.n2.co.b > 0 && this.nf != null && !this.nf.cn()) {
                        this.jl(true);
                    }
                    break;
                case 3:
                    if (d == this.ok) {
                        if (this.nf != null && !this.nf.cn()) {
                            this.jl(true);
                        }
                    }
                    break;
            }
        }
        dw(a, b, c) {
            let d = super.dw(a, b, c);
            let e = c;
            if (this.bz == null || this.bz.count == 0 || this.nd == null || this.n8 == null || this.nd.j7 == 0 || this.nf == null || isInfinity(this.nf.kc) || isInfinity(this.nf.kb) || e.co.b < 1) {
                d = false;
            }
            return d;
        }
        getOffsetValue() {
            return this.od(this.nd, this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
        }
        getCategoryWidth() {
            return this.nd.getCategorySize(this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
        }
        get_ob() {
            return false;
        }
        get ob() {
            return this.get_ob();
        }
        od(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.nr(), b, c, d);
                    break;
            }
            if (a.ca) {
                e = -e;
            }
            return e;
        }
        nw(a, b) {
            let c = b.bs;
            let d = b.br;
            let e = this.getEffectiveViewport1(b);
            let f = this.nd;
            let g = this.nf;
            let h = g.kc;
            let i = g.kb;
            a.f.clear();
            a.m.clear();
            a.p.clear();
            let j = this.md();
            let k = 0;
            let l = b;
            let m = new CollisionAvoider();
            let n = 0;
            let o = b.co.d;
            n = this.od(f, c, d, e);
            l.ct.i = this.nf.lr;
            l.ct.h = this.nf.lq;
            l.ct.j = (p, q) => this.oe(p, q, c, d);
            l.ct.k = (p, q) => this.of(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.co.b;
                $ret.d = b.co.c;
                $ret.e = o;
                $ret.a = n;
                $ret.b = this.eu;
                $ret.f = d;
                $ret.g = c;
                return $ret;
            })());
            l.ct.l(a.p, this.n6, this.n8, this.oh, (r) => this.nd.getScaledAngle(r), (r) => this.nf.lx(r), q, p);
            let r = true;
            if (this.oc(b)) {
                o--;
            }
            for (let s = b.co.c; s <= o; ++s) {
                let t = s;
                if (t * b.co.b >= this.nd.j7) {
                    t -= intDivide((this.nd.j7), b.co.b);
                }
                let u = b.co.getBucket(t);
                if (!isNaN_(u[0])) {
                    u[0] = f.getScaledAngle(u[0]) + n;
                    if (u[1] < h || u[1] > i) {
                        continue;
                    }
                    u[1] = g.lx(u[1]);
                    if (b.co.b > 1) {
                        if (u[2] < h || u[2] > i) {
                            continue;
                        }
                        u[2] = g.lx(u[2]);
                    }
                    else {
                        u[2] = u[1];
                    }
                    if ((isNaN_(u[1]) || isNaN_(u[2])) && r && this.ob && this.oa()) {
                        o++;
                    }
                    else {
                        r = false;
                    }
                    a.f.add(u);
                    if (j) {
                        let v = Math.min(t * b.co.b, this.bz.count - 1);
                        let w = this.ng.d(u[0], u[1], c, d);
                        let x = this.ng.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.cp.item(k);
                            z.ak = v;
                            z.content.item = this.bz.item(v);
                            ++k;
                        }
                    }
                }
                else {
                    if (r && this.ob && this.oa()) {
                        o++;
                    }
                }
            }
            b.cp.count = k;
            return;
        }
        oe(a, b, c, d) {
            return this.ng.d(a, b, c, d);
        }
        of(a, b, c, d) {
            return this.ng.e(a, b, c, d);
        }
        oc(a) {
            let b = a;
            return !this.ob && b.co.c == 0 && b.co.d == this.nd.j7;
        }
        n1(a, b, c) {
            let d = null;
            let e = c.bs;
            let f = c.br;
            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;
        }
        on(a, b, c, d, e) {
            if (a.count > 0 && d.count > 0) {
                if (!e || this.n9()) {
                    a.add(this.o1);
                    a.add(a._inner[0]);
                    d.add(this.o1);
                    d.add(d._inner[0]);
                }
            }
        }
        oa() {
            return !this.n9();
        }
        n9() {
            let a = this.bi.bs;
            return !a.containsPoint({ $type: Point_$type, x: 0.5, y: 0.5 });
        }
        h3(a, b) {
            super.h3(a, b);
            let c = b;
            if (a) {
                c.cp.clear();
            }
            c.ct.g$d();
        }
        nx(a, b) {
            let c = b.bs;
            let d = b.br;
            let e = this.getEffectiveViewport1(b);
            let f = this.l0(b);
            let g = b;
            g.ct.g$g(a.p);
            CategoryMarkerManager.b(this, a.m, g.cp, this.mf);
            g.cj();
            this.om(d, c, e, f, g);
        }
        om(a, b, c, d, e) {
            e.cu(a, b, c, d);
        }
        jw() {
            super.jw();
            if (this.fh < 0) {
                return;
            }
            this.n2.cv();
        }
        fv(a, b) {
            if (a == this.n2.ct.g$j) {
                return null;
            }
            return super.fv(a, b);
        }
        c9(a) {
            let b = this.bi.bs;
            b = b.copy();
            let c = this.bi.br;
            let d = !b.isEmpty && !c.isEmpty && this.bz != null ? this.bz.indexOf(a) : -1;
            if (this.nd == null || this.n8 == null || this.nf == null) {
                return false;
            }
            if (d < 0 || d > this.n8.count - 1) {
                return false;
            }
            let e = this.nd.getScaledAngle(d);
            let f = this.nf.lx(this.n8.item(d));
            if (isNaN_(f)) {
                f = (this.nf.lq + this.nf.lr) / 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.bn != null) {
                this.bn.ap(this.bs, b, true);
            }
            return d >= 0;
        }
        jn(a, b) {
            super.jn(a, b);
            if (!this.dl) {
                this.bi.az(b);
                return;
            }
            this.bi.az(b);
            let c = typeCast(AnchoredRadialSeriesView.$, this.bh);
            c.co.e(this.eu);
            if (this.cc(this.bh)) {
                return;
            }
            if (!this.df) {
                this.n5 = new RadialFrame(3);
                this.nw(this.n5, c);
            }
            this.df = false;
            this.nx(this.n5, c);
            this.dl = false;
        }
        jk(a, b, c, d, e) {
            super.jk(a, b, c, d, e);
            let f = this.a0.a$h.item(d);
            let g = f;
            g.co.e(this.eu);
            f.ay(c);
            if (this.cc(g)) {
                return;
            }
            if (this.n4 == null) {
                this.n4 = new RadialFrame(3);
            }
            this.n4.u();
            this.nw(this.n4, g);
            this.nx(this.n4, g);
        }
        ic(a) {
            super.ic(a);
            this.a2.exportTrendlineData(this, a, this.n2.ct.g$j);
        }
    }
    AnchoredRadialSeries.$t = /*@__PURE__*/ markType(AnchoredRadialSeries, 'AnchoredRadialSeries', RadialBase.$);
    AnchoredRadialSeries.oo = /*@__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:ok:ow', [2, null], 'TrendLineType:n6:ou', [TrendLineType_$type, /*@__PURE__*/ enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness:og:ot', [1, 1.5], 'TrendLinePeriod:oh:os', [1, 7], 'TrendLineZIndex:oi:ov', [1, 1], 'TrendLineBrush:oy:op', [Brush.$, null], 'TrendLineDashArray:oz:oq', [DoubleCollection.$], 'TrendLineDashCap:o0:or', [PenLineCap_$type, /*@__PURE__*/ enumGetBox(PenLineCap_$type, 0)]]);
    return AnchoredRadialSeries;
})();
/**
 * @hidden
 */
export let AnchoredRadialSeriesView = /*@__PURE__*/ (() => {
    class AnchoredRadialSeriesView extends RadialBaseView {
        constructor(a) {
            super(a);
            this.cs = null;
            this.ct = null;
            this.co = new AnchoredRadialBucketCalculator(this);
            this.cs = a;
            this.ct = new RadialTrendLineManager();
        }
        cu(a, b, c, d) {
        }
        cv() {
            this.cs.ox = null;
            if (this.cs.oy != null) {
                this.cs.ox = this.cs.oy;
            }
            else {
                this.cs.ox = this.cs.lb;
            }
        }
        a2(a, b) {
            if (a.d) {
                if (!b) {
                }
                if (this.cs.n6 != 0 && !b) {
                    let c = this.ct.g$j;
                    c.ac = this.cs.og;
                    c._stroke = this.cs.ox;
                    c.ai = this.cs.oz;
                    c.ad = this.cs.o0;
                    a.u(c);
                }
            }
            super.a2(a, b);
        }
        getDefaultTooltipTemplate() {
            let a = "<div class='ui-chart-default-tooltip-content'>";
            if (this.cs.nd.e9 != null) {
                a += "<span>${item." + this.cs.nd.e9 + "}</span><br/>";
            }
            a += "<span";
            let b = this.e.a0.a$q(this.e);
            if (!stringIsNullOrEmpty(b)) {
                a += " style='color:" + b + "'";
            }
            a += ">" + this.cs.fx + ": </span><span class='ui-priority-primary'>" + "${item." + this.cs.ok + "}</span></div>";
            return a;
        }
    }
    AnchoredRadialSeriesView.$t = /*@__PURE__*/ markType(AnchoredRadialSeriesView, 'AnchoredRadialSeriesView', RadialBaseView.$);
    return AnchoredRadialSeriesView;
})();
//# sourceMappingURL=AnchoredRadialBucketCalculator_combined.js.map
