/*
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-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 { 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 class AnchoredRadialBucketCalculator extends RadialBucketCalculator {
    constructor(a) {
        super(a);
        this.f = null;
        this.f = a;
    }
    getBucket(a) {
        let b = this.f.cs.nw;
        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.$);
/**
 * @hidden
 */
export class AnchoredRadialSeries extends RadialBase {
    constructor() {
        super();
        this.nr = null;
        this.nv = null;
        this.op = { $type: Point_$type, x: 0, y: 0 };
        this.nt = null;
        this.ns = null;
        this.nt = new RadialFrame(3);
        this.nr = new CategoryLineRasterizer();
    }
    bf() {
        return new AnchoredRadialSeriesView(this);
    }
    ht() {
        super.ht();
        this.m0 = null;
        this.m2 = null;
    }
    fs(a, b) {
        let c = this.gu(b);
        if (c == AnchoredRadialSeries.$$p[0]) {
            return this.ft(a, b, this.n8);
        }
        return super.fs(a, b);
    }
    iu(a) {
        super.iu(a);
        this.nq = a;
    }
    fe(a, b) {
        return this.ff(a, b, this.m0, null, this.nw);
    }
    fc(a, b) {
        return this.fd(a, b, this.m0, null, this.nw);
    }
    d9(a, b, c, d, e) {
        if (this.nw == null) {
            return Number.POSITIVE_INFINITY;
        }
        return this.ea(a, b, this.m0, d, e, this.nw.count, null);
    }
    en(a, b, c) {
        let d = this.getEffectiveViewport1(this.bi);
        let e = this.n1(this.m0, this.bi.bs, this.bi.br, d);
        let f = new ScalerParams(0, this.bi.bs, this.bi.br, this.m0.b8, d);
        f.c = this.bs.m3;
        return this.ep(this.nw, a, this.m0, f, e, null, b, c);
    }
    ll(a, b, c) {
        if (this.m2 == null || this.m0 == 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.m2.b8, d);
        e.c = this.getEffectiveViewport1(this.bi);
        let f = this.en(a, b, c);
        f = this.m2.dw(f, e);
        let g = this.m3.c(a);
        if (!b && this.m0 != null) {
            let h = this.fe(a, c);
            let i = this.fc(a, c);
            let j = this.n1(this.m0, this.bi.bs, this.bi.br, d);
            let k = new ScalerParams(0, this.bi.bs, this.bi.br, this.m0.b8, d);
            k.c = this.bs.m3;
            let l = this.d9(a, h, this.m0, k, j);
            let m = this.d9(a, i, this.m0, k, j);
            if (m <= l) {
                g = this.m0.dw(i, k) + j;
            }
            else {
                g = this.m0.dw(h, k) + j;
            }
        }
        let n = this.m3.d(g, f, this.bi.bs, this.bi.br);
        let o = this.m3.e(g, f, this.bi.bs, this.bi.br);
        return { $type: Point_$type, x: n, y: o };
    }
    get nw() {
        return this.nv;
    }
    set nw(a) {
        if (this.nv != a) {
            let b = this.nv;
            this.nv = a;
            this.raisePropertyChanged("ValueColumn", b, this.nv);
        }
    }
    get ol() {
        return this.c(AnchoredRadialSeries.oc);
    }
    set ol(a) {
        this.h(AnchoredRadialSeries.oc, a);
    }
    an(a) {
        if (a != null && a == this.m0 && this.nw != null && this.nw.count > 0) {
            return new AxisRange(0, this.nw.count - 1);
        }
        if (a != null && a == this.m2 && this.nw != null && this.nw.count > 0) {
            return new AxisRange(this.nw.minimum, this.nw.maximum);
        }
        return null;
    }
    iz(a, b, c, d) {
        super.iz(a, b, c, d);
        if (this.nq.ct.g$b(a, b, c, d)) {
            this.jd(false);
            this.ik();
        }
        let e = typeCast(NumericAxisBase.$, this.m2);
        switch (b) {
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) !== null) {
                    c.deregisterColumn(this.nw);
                    this.nw = null;
                }
                if (typeCast(IFastItemsSource_$type, d) !== null) {
                    this.nw = this.bw(this.n8);
                    this.nq.co.e(this.eu);
                }
                if (e != null && !e.cl()) {
                    this.nq.co.e(this.eu);
                    this.jd(false);
                }
                break;
            case AnchoredRadialSeries.$$p[0]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nw);
                    this.nw = this.bw(this.n8);
                }
                break;
            case "ValueColumn":
                if (e != null && !e.cl()) {
                    this.nq.co.e(this.eu);
                    this.jd(false);
                }
                break;
            case "TrendLineBrush":
                this.jo();
                break;
            case "TrendLineType":
                this.ik();
                break;
        }
    }
    hy(a, b, c, d) {
        switch (a) {
            case 4:
            case 1:
            case 0:
                this.nq.co.e(this.eu);
                break;
        }
        this.nq.ct.g$e(a, b, c, d);
        switch (a) {
            case 4:
                if (this.m2 != null && !this.m2.cl()) {
                    this.jd(true);
                }
                break;
            case 1:
                if (this.m2 != null && !this.m2.cl()) {
                    this.jd(true);
                }
                break;
            case 0:
                if (this.m2 != null && !this.m2.cl()) {
                    this.jd(true);
                }
                break;
            case 2:
                if (this.n8 != null && this.nq.co.b > 0 && this.m2 != null && !this.m2.cl()) {
                    this.jd(true);
                }
                break;
            case 3:
                if (d == this.n8) {
                    if (this.m2 != null && !this.m2.cl()) {
                        this.jd(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.m0 == null || this.nw == null || this.m0.jy == 0 || this.m2 == null || isInfinity(this.m2.j4) || isInfinity(this.m2.j3) || e.co.b < 1) {
            d = false;
        }
        return d;
    }
    getOffsetValue() {
        return this.n1(this.m0, this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
    }
    getCategoryWidth() {
        return this.m0.getCategorySize(this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
    }
    get_nz() {
        return false;
    }
    get nz() {
        return this.get_nz();
    }
    n1(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.nf(), b, c, d);
                break;
        }
        if (a.b8) {
            e = -e;
        }
        return e;
    }
    nk(a, b) {
        let c = b.bs;
        let d = b.br;
        let e = this.getEffectiveViewport1(b);
        let f = this.m0;
        let g = this.m2;
        let h = g.j4;
        let i = g.j3;
        a.f.clear();
        a.m.clear();
        a.p.clear();
        let j = this.l3();
        let k = 0;
        let l = b;
        let m = new CollisionAvoider();
        let n = 0;
        let o = b.co.d;
        n = this.n1(f, c, d, e);
        l.ct.q = this.m2.lj;
        l.ct.p = this.m2.li;
        l.ct.r = (p, q) => this.n2(p, q, c, d);
        l.ct.s = (p, q) => this.n3(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.t(a.p, this.nu, this.nw, this.n5, (r) => this.m0.getScaledAngle(r), (r) => this.m2.lp(r), q, p);
        let r = true;
        if (this.n0(b)) {
            o--;
        }
        for (let s = b.co.c; s <= o; ++s) {
            let t = s;
            if (t * b.co.b >= this.m0.jy) {
                t -= intDivide((this.m0.jy), 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.lp(u[1]);
                if (b.co.b > 1) {
                    if (u[2] < h || u[2] > i) {
                        continue;
                    }
                    u[2] = g.lp(u[2]);
                }
                else {
                    u[2] = u[1];
                }
                if ((isNaN_(u[1]) || isNaN_(u[2])) && r && this.nz && this.ny()) {
                    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.m3.d(u[0], u[1], c, d);
                    let x = this.m3.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.nz && this.ny()) {
                    o++;
                }
            }
        }
        b.cp.count = k;
        return;
    }
    n2(a, b, c, d) {
        return this.m3.d(a, b, c, d);
    }
    n3(a, b, c, d) {
        return this.m3.e(a, b, c, d);
    }
    n0(a) {
        let b = a;
        return !this.nz && b.co.c == 0 && b.co.d == this.m0.jy;
    }
    np(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;
    }
    ob(a, b, c, d, e) {
        if (a.count > 0 && d.count > 0) {
            if (!e || this.nx()) {
                a.add(this.op);
                a.add(a._inner[0]);
                d.add(this.op);
                d.add(d._inner[0]);
            }
        }
    }
    ny() {
        return !this.nx();
    }
    nx() {
        let a = this.bi.bs;
        return !a.containsPoint({ $type: Point_$type, x: 0.5, y: 0.5 });
    }
    hv(a, b) {
        super.hv(a, b);
        let c = b;
        if (a) {
            c.cp.clear();
        }
        c.ct.g$d();
    }
    nl(a, b) {
        let c = b.bs;
        let d = b.br;
        let e = this.getEffectiveViewport1(b);
        let f = this.lq(b);
        let g = b;
        g.ct.g$g(a.p);
        CategoryMarkerManager.b(this, a.m, g.cp, this.l5);
        g.cj();
        this.oa(d, c, e, f, g);
    }
    oa(a, b, c, d, e) {
        e.cu(a, b, c, d);
    }
    jo() {
        super.jo();
        if (this.fh < 0) {
            return;
        }
        this.nq.cv();
    }
    fv(a, b) {
        if (a == this.nq.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.m0 == null || this.nw == null || this.m2 == null) {
            return false;
        }
        if (d < 0 || d > this.nw.count - 1) {
            return false;
        }
        let e = this.m0.getScaledAngle(d);
        let f = this.m2.lp(this.nw.item(d));
        if (isNaN_(f)) {
            f = (this.m2.li + this.m2.lj) / 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;
    }
    jf(a, b) {
        super.jf(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.nt = new RadialFrame(3);
            this.nk(this.nt, c);
        }
        this.df = false;
        this.nl(this.nt, c);
        this.dl = false;
    }
    jc(a, b, c, d, e) {
        super.jc(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.ns == null) {
            this.ns = new RadialFrame(3);
        }
        this.ns.u();
        this.nk(this.ns, g);
        this.nl(this.ns, g);
    }
    h4(a) {
        super.h4(a);
        this.a2.exportTrendlineData(this, a, this.nq.ct.g$j);
    }
}
AnchoredRadialSeries.$t = markType(AnchoredRadialSeries, 'AnchoredRadialSeries', RadialBase.$);
AnchoredRadialSeries.oc = 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', ['ValueMemberPath:n8:ok', [2, null], 'TrendLineType:nu:oi', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness:n4:oh', [1, 1.5], 'TrendLinePeriod:n5:og', [1, 7], 'TrendLineZIndex:n6:oj', [1, 1], 'TrendLineBrush:om:od', [Brush.$, null], 'TrendLineDashArray:on:oe', [DoubleCollection.$], 'TrendLineDashCap:oo:of', [PenLineCap_$type, enumGetBox(PenLineCap_$type, 0)]]);
/**
 * @hidden
 */
export 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.ol = null;
        if (this.cs.om != null) {
            this.cs.ol = this.cs.om;
        }
        else {
            this.cs.ol = this.cs.k3;
        }
    }
    a2(a, b) {
        if (a.d) {
            if (!b) {
            }
            if (this.cs.nu != 0 && !b) {
                let c = this.ct.g$j;
                c.ac = this.cs.n4;
                c._stroke = this.cs.ol;
                c.ai = this.cs.on;
                c.ad = this.cs.oo;
                a.u(c);
            }
        }
        super.a2(a, b);
    }
    getDefaultTooltipTemplate() {
        let a = "<div class='ui-chart-default-tooltip-content'>";
        if (this.cs.m0.e7 != null) {
            a += "<span>${item." + this.cs.m0.e7 + "}</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.n8 + "}</span></div>";
        return a;
    }
}
AnchoredRadialSeriesView.$t = markType(AnchoredRadialSeriesView, 'AnchoredRadialSeriesView', RadialBaseView.$);
//# sourceMappingURL=AnchoredRadialBucketCalculator_combined.js.map