/*
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 { MarkerSeries } from "./MarkerSeries";
import { Base, Type, runOn, Number_$type, enumGetBox, typeCast, Point_$type, fromEnum, markType } from "igniteui-react-core/ES2015/type";
import { PolarAxisInfoCache } from "./PolarAxisInfoCache";
import { SeriesRenderer$2 } from "./SeriesRenderer$2";
import { PolarFrame } from "./PolarFrame";
import { DependencyProperty } from "igniteui-react-core/ES2015/DependencyProperty";
import { NumericAngleAxis } from "./NumericAngleAxis";
import { NumericRadiusAxis } from "./NumericRadiusAxis";
import { TrendLineType_$type } from "igniteui-react-core/ES2015/TrendLineType";
import { Brush } from "igniteui-react-core/ES2015/Brush";
import { PenLineCap_$type } from "igniteui-react-core/ES2015/PenLineCap";
import { DoubleCollection } from "igniteui-react-core/ES2015/DoubleCollection";
import { List$1 } from "igniteui-react-core/ES2015/List$1";
import { SeriesPointOfInterest } from "./SeriesPointOfInterest";
import { ScalerParams } from "./ScalerParams";
import { Rect } from "igniteui-react-core/ES2015/Rect";
import { Marker } from "./Marker";
import { MarkerSeriesView } from "./MarkerSeriesView";
import { PolarAxes } from "./PolarAxes";
import { IFastItemsSource_$type } from "igniteui-react-core/ES2015/IFastItemsSource";
import { SeriesRenderingArguments } from "./SeriesRenderingArguments";
import { AxisRange } from "./AxisRange";
import { HashPool$2 } from "igniteui-react-core/ES2015/HashPool$2";
import { Clipper } from "igniteui-react-core/ES2015/Clipper";
import { Dictionary$2 } from "igniteui-react-core/ES2015/Dictionary$2";
import { OwnedPoint } from "./OwnedPoint";
import { PolarTrendLineManager } from "./PolarTrendLineManager";
import { TrendResolutionParams } from "./TrendResolutionParams";
import { PropertyMetadata } from "igniteui-react-core/ES2015/PropertyMetadata";
import { isNaN_, isInfinity } from "igniteui-react-core/ES2015/number";
import { NumericMarkerManager } from "./NumericMarkerManager";
import { GeometryGroup } from "igniteui-react-core/ES2015/GeometryGroup";
import { stringIsNullOrEmpty } from "igniteui-react-core/ES2015/string";
export class PolarBase extends MarkerSeries {
    constructor() {
        super();
        this.mz = null;
        this.ms = null;
        this.mx = null;
        this.op = null;
        this.oo = null;
        this.m5 = null;
        this.m7 = null;
        this.m8 = null;
        this.m2 = new PolarFrame();
        this.m4 = new PolarFrame();
        this.m1 = new PolarFrame();
        this.mw = null;
        this.m3 = null;
        this.m0 = null;
        this.m3 = new PolarFrame();
        this.m4.x = runOn(this, this.on);
        this.m2.x = runOn(this, this.on);
        this.m1.x = runOn(this, this.on);
        this.m5 = new SeriesRenderer$2(PolarFrame.$, PolarBaseView.$, 0, runOn(this, this.n0), runOn(this, this.n2), runOn(this, this.ca), runOn(this, this.jc), runOn(this, this.ny));
    }
    bf() {
        return new PolarBaseView(this);
    }
    il(a) {
        super.il(a);
        this.my = a;
    }
    hm() {
        super.hm();
        this.mu = null;
        this.mv = null;
    }
    get_c0() {
        return true;
    }
    ne(a) {
        if (!this.hasMarkers) {
            return false;
        }
        let b = this.mu;
        let c = new ScalerParams(1, this.bs.mn, this.lp, b.b8);
        c.c = this.getEffectiveViewport1(this.bi);
        let d = this.mv;
        let e = new ScalerParams(1, this.bs.mn, this.lp, d.b8);
        e.c = this.getEffectiveViewport1(this.bi);
        a.clear();
        this.lr.cc((f) => {
            if (f._visibility == 0) {
                let g = new SeriesPointOfInterest();
                let h = f.n;
                let i = f.o;
                if (h < this.lp.left || h > this.lp.right || i < this.lp.top || i > this.lp.bottom) {
                    return;
                }
                g.b = b.dw(h, c);
                g.c = d.dw(i, e);
                g.a = f.content;
                a.add(g);
            }
        });
        return true;
    }
    ny() {
        if (this.bt.g) {
            this.bt.t();
        }
    }
    nz() {
        this.mw.e(this.mz.w, this.m9, this.na, this.op, this.oo, (a, b) => Math.cos(b), (a, b) => Math.sin(b), true);
    }
    get m9() {
        return this.m7;
    }
    set m9(a) {
        if (this.m7 != a) {
            let b = this.m9;
            this.m7 = a;
            this.raisePropertyChanged("AngleColumn", b, this.m9);
        }
    }
    get na() {
        return this.m8;
    }
    set na(a) {
        if (this.m8 != a) {
            let b = this.na;
            this.m8 = a;
            this.raisePropertyChanged("RadiusColumn", b, this.na);
        }
    }
    get oi() {
        return this.c(PolarBase.n3);
    }
    set oi(a) {
        this.h(PolarBase.n3, a);
    }
    h3() {
        super.h3();
        if (this.mv != null) {
            this.mv.g0(false);
        }
        if (this.mu != null) {
            this.mu.g0(false);
        }
    }
    hr(a, b, c, d) {
        let e = false;
        this.my.cr.g$e(a, b, c, d);
        if (this.mu != null && !this.mu.ck()) {
            e = true;
        }
        if (this.mv != null && !this.mv.ck()) {
            e = true;
        }
        if (e) {
            this.i4(true);
        }
    }
    jj(a, b) {
        this.i4(false);
    }
    jk(a, b) {
        this.i4(false);
    }
    du(a, b, c) {
        let d = true;
        if (!super.du(a, b, c) || !c.l() || b.isEmpty || a.isEmpty || this.mu == null || this.mv == null || this.m9 == null || this.na == null || this.m9.count == 0 || this.na.count == 0 || this.bz == null || this.bz.count != this.m9.count || this.bz.count != this.na.count || this.mw == null || this.mu.bf == null || this.mv.bf == null || this.mu.jx == this.mu.jw || this.mv.jx == this.mv.jw) {
            d = false;
        }
        return d;
    }
    i5(a) {
        let b;
        let c;
        let d = this.getViewInfo(c, b);
        c = d.p0;
        b = d.p1;
        if (!this.du(c, b, this.bi)) {
            this.ho(true, this.bi);
            return;
        }
        this.op = b;
        this.oo = c;
        this.mx = new PolarAxisInfoCache(this.mu, this.mv, this.bz);
        let e = new SeriesRenderingArguments(this, c, b, a, this.dc);
        let f = this.m5.g(e, this.m2, this.m1, this.m4, this.my);
        this.m2 = f.p1;
        this.m1 = f.p2;
        this.m4 = f.p3;
    }
    on(a) {
        let b = this.mw.h(a.x, a.y, this.op, this.oo, this.mx.e, this.mx.d, this.mx.g, this.mx.f, this.mx.i, this.mx.h);
        return b;
    }
    an(a) {
        if (a != null && a == this.mu && this.m9 != null) {
            return new AxisRange(this.m9.minimum, this.m9.maximum);
        }
        if (a != null && a == this.mv && this.na != null) {
            return new AxisRange(this.na.minimum, this.na.maximum);
        }
        return null;
    }
    c7(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.mu == null || this.m9 == null || this.mv == null || this.na == null) {
            return false;
        }
        if (d < 0 || d > this.m9.count - 1 || d > this.na.count - 1) {
            return false;
        }
        let e = this.mu.getScaledAngle(this.m9.item(d));
        let f = this.mv.li(this.na.item(d));
        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;
    }
    fl(a) {
        return null;
    }
    e4(a) {
        return -1;
    }
    ag() {
        return [this.mu, this.mv];
    }
    ir(a, b, c, d) {
        super.ir(a, b, c, d);
        if (this.my.cr.g$b(a, b, c, d)) {
            this.i4(false);
            this.ib();
        }
        switch (b) {
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.m9);
                    c.deregisterColumn(this.na);
                    this.m9 = null;
                    this.na = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.m9 = this.bw(this.nn);
                    this.na = this.bw(this.nt);
                }
                if ((this.mv != null && !this.mv.ck()) || (this.mu != null && !this.mu.ck())) {
                    this.i4(false);
                }
                break;
            case PolarBase.$$p[0]:
                if (this.mu != null && this.mv != null) {
                    this.mw = new PolarAxes(this.mv, this.mu);
                }
                if (c != null) {
                    c.bv(this);
                }
                if (d != null) {
                    d.ch(this);
                }
                if (this.mu != null && !this.mu.ck()) {
                    this.i4(false);
                }
                else if (c != null && d == null) {
                    this.ho(true, this.bi);
                }
                break;
            case PolarBase.$$p[4]:
                if (this.mu != null && this.mv != null) {
                    this.mw = new PolarAxes(this.mv, this.mu);
                }
                if (c != null) {
                    c.bv(this);
                }
                if (d != null) {
                    d.ch(this);
                }
                if (this.mv != null && !this.mv.ck()) {
                    this.i4(false);
                }
                else if (c != null && d == null) {
                    this.ho(true, this.bi);
                }
                if (this.mu != null && !this.mu.ck()) {
                    this.mu.gw();
                }
                break;
            case PolarBase.$$p[1]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.m9);
                    this.m9 = this.bw(this.nn);
                }
                break;
            case "AngleColumn":
                this.my.cr.g$i();
                if (this.mu != null && !this.mu.ck()) {
                    this.i4(false);
                }
                break;
            case PolarBase.$$p[5]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.na);
                    this.na = this.bw(this.nt);
                }
                break;
            case "RadiusColumn":
                this.my.cr.g$i();
                if (this.mv != null && !this.mv.ck()) {
                    this.i4(false);
                }
                break;
            case PolarBase.$$p[6]:
                this.i4(false);
                this.ib();
                break;
            case PolarBase.$$p[3]:
                this.i4(false);
                this.ib();
                break;
            case "TransitionProgress":
                this.mx = new PolarAxisInfoCache(this.mu, this.mv, this.bz);
                this.op = this.bi.bs;
                this.oo = this.bi.br;
                this.m4.v = this.nf;
                this.m4.c(this.ev, this.m2, this.m1);
                if (this.cc(this.bi)) {
                    return;
                }
                if (this.ev == 1) {
                    this.n2(this.m1, this.my);
                }
                else {
                    this.n2(this.m4, this.my);
                }
                if (this.bs != null) {
                    this.bs.jh(this);
                }
                break;
            case "TrendLineBrush":
                this.jf();
                break;
            case PolarBase.$$p[2]:
                this.i4(false);
                this.ib();
                break;
            case "TrendLineType":
                this.ib();
                break;
        }
    }
    nc(a) {
        if (typeCast(NumericRadiusAxis.$, a) !== null) {
            return true;
        }
        return false;
    }
    nb(a) {
        if (typeCast(NumericAngleAxis.$, a) !== null) {
            return true;
        }
        return false;
    }
    ho(a, b) {
        super.ho(a, b);
        let c = b;
        if (a) {
            c.cs.clear();
        }
        c.cr.g$d();
    }
    mt(a, b) {
        let c = a.top - 10;
        let d = a.bottom + 10;
        let e = a.left - 10;
        let f = a.right + 10;
        let g = ((() => {
            let $ret = new Clipper(1, e, d, f, c, false);
            $ret.i = b;
            return $ret;
        })());
        return g;
    }
    nx(a, b, c, d) {
        a.g = new Dictionary$2(Base.$, OwnedPoint.$, 1, b);
        let e = this.bz;
        for (let f = 0; f < b; f++) {
            let g = a.w._inner[f];
            if (!isInfinity(g.x) && !isInfinity(g.y)) {
                let h = { $type: Point_$type, x: this.m9.item(f), y: this.na.item(f) };
                let i = { $type: Point_$type, x: g.x, y: g.y };
                a.g.addItem(e.item(f), ((() => {
                    let $ret = new OwnedPoint();
                    $ret.a = e.item(f);
                    $ret.b = h;
                    $ret.c = i;
                    return $ret;
                })()));
            }
        }
    }
    n0(a, b) {
        let c = b.bs;
        let d = b.br;
        a.j.clear();
        a.n.clear();
        let e = Math.min(this.m9 != null ? this.m9.count : 0, this.na != null ? this.na.count : 0);
        if (e < 1) {
            return;
        }
        this.mx = new PolarAxisInfoCache(this.mu, this.mv, this.bz);
        this.mz = a;
        this.oo = d;
        this.op = c;
        b.cp.l(a.j, this.ni, c, d, this.eq);
        if (e <= this.ni) {
            this.nx(a, e, c, d);
        }
        let f = this.mt(d, a.n);
        let g = Math.min(this.mu.jx, this.mu.jw);
        let h = Math.max(this.mu.jw, this.mu.jx);
        b.cr.q = this.nf;
        b.cr.p = 0;
        b.cr.s = this.mv.lc;
        b.cr.r = this.mv.lb;
        b.cr.t = (i, j) => this.mw.c(i, j, c, d, Math.cos);
        b.cr.u = (i, j) => this.mw.d(i, j, c, d, Math.sin);
        let i = new List$1(Number_$type, 0);
        for (let j = 0; j < this.m9.count; j++) {
            if (this.m9.item(j) >= g && this.m9.item(j) <= h) {
                i.add(this.m9.item(j));
            }
        }
        let k = this.na;
        if (i.count != this.m9.count) {
            k = new List$1(Number_$type, 0);
            for (let l = 0; l < this.m9.count; l++) {
                if (this.m9.item(l) >= g && this.m9.item(l) <= h) {
                    k.add(this.na.item(l));
                }
            }
        }
        b.cr.v(a.n, this.m6, i, k, this.nj, runOn(this.mu, this.mu.getScaledAngle), runOn(this.mv, this.mv.li), ((() => {
            let $ret = new TrendResolutionParams();
            $ret.b = this.eq;
            $ret.f = d;
            $ret.g = c;
            return $ret;
        })()), f, g, h);
    }
    n2(a, b) {
        let c = b.bs;
        let d = b.br;
        let e = this.getEffectiveViewport1(b);
        let f = this.lh(b);
        this.mx = new PolarAxisInfoCache(this.mu, this.mv, this.bz);
        b.cp.j(a.j, this.lw);
        b.cj();
        let g = this.mt(d, b.cr.g$j.aj);
        b.cr.g$h(a.n, g);
        this.nw(d, c, e, f, b);
    }
    nw(a, b, c, d, e) {
        e.cu(a, b, c, d);
    }
    jf() {
        super.jf();
        if (this.fd < 0) {
            return;
        }
        this.my.cw();
    }
    i6(a, b) {
        super.i6(a, b);
        if (!this.dj) {
            this.bi.az(b);
            return;
        }
        this.bi.az(b);
        if (this.cc(this.bh)) {
            return;
        }
        let c = this.bh;
        if (!this.dd) {
            this.m3 = new PolarFrame();
            this.n0(this.m3, c);
        }
        this.dd = false;
        this.n2(this.m3, c);
        this.dj = false;
    }
    i3(a, b, c, d, e) {
        super.i3(a, b, c, d, e);
        let f = this.a0.a$h.item(d);
        let g = f;
        f.ay(c);
        if (this.cc(g)) {
            return;
        }
        if (this.m0 == null) {
            this.m0 = new PolarFrame();
        }
        this.n0(this.m0, g);
        this.n2(this.m0, g);
    }
    n1(a, b) {
        let c = new List$1(Base.$, 0);
        for (let d of fromEnum(b.c)) {
            if (!a.containsKey(d)) {
                c.add1(d);
            }
        }
        for (let e of fromEnum(c)) {
            b.g(e);
        }
    }
    mr(a, b, c) {
        this.nz();
        return this.mz.w.toArray();
    }
    ng(a) {
        let b = new List$1(Number_$type, 0);
        let c = this.bz;
        for (let d of fromEnum(this.my.cs.c)) {
            b.add(c.indexOf(d));
        }
        return b;
    }
    om(a) {
        return { $type: Point_$type, x: this.m9.item(a), y: this.na.item(a) };
    }
    hx(a) {
        super.hx(a);
        this.a2.exportTrendlineData(this, a, this.my.cr.g$j);
    }
}
PolarBase.$t = markType(PolarBase, 'PolarBase', MarkerSeries.$);
PolarBase.n3 = DependencyProperty.i("ActualTrendLineBrush", Brush.$, PolarBase.$, new PropertyMetadata(2, null, (a, b) => a.raisePropertyChanged("ActualTrendLineBrush", b.oldValue, b.newValue)));
Type.dep(DependencyProperty, PropertyMetadata, PolarBase, 'raisePropertyChanged', ['AngleAxis:mu:n4', [NumericAngleAxis.$, null], 'AngleMemberPath:nn:n5', [2], 'ClipSeriesToBounds:nd:n6', [0, false], 'MaximumMarkers:ni:n7', [1, 400], 'RadiusAxis:mv:n8', [NumericRadiusAxis.$, null], 'RadiusMemberPath:nt:n9', [2], 'UseCartesianInterpolation:nf:oh', [0, true], 'TrendLineType:m6:of', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness:nh:oe', [1, 1.5], 'TrendLinePeriod:nj:od', [1, 7], 'TrendLineZIndex:nk:og', [1, 1], 'TrendLineBrush:oj:oa', [Brush.$, null], 'TrendLineDashArray:ok:ob', [DoubleCollection.$], 'TrendLineDashCap:ol:oc', [PenLineCap_$type, enumGetBox(PenLineCap_$type, 0)]]);
export class PolarBaseView extends MarkerSeriesView {
    constructor(a) {
        super(a);
        this.cq = null;
        this.cp = null;
        this.cr = null;
        this.cs = null;
        this.cq = a;
        this.cs = new HashPool$2(Base.$, Marker.$);
        this.ce(this.cs);
        this.cr = new PolarTrendLineManager();
    }
    ap() {
        super.ap();
        this.cp = this.co();
        if (!this.n) {
            this.cq.ni = 1000;
            this.by.ls = 2;
        }
    }
    co() {
        let a = new NumericMarkerManager(0, (b) => this.cs.item(b), (b) => this.cq.mx.c.item(b), runOn(this, this.cv), runOn(this, this.cn), runOn(this, this.ct));
        a.n = true;
        a.p = runOn(this.cq, this.cq.om);
        return a;
    }
    cv(a) {
        this.cq.n1(a, this.cs);
    }
    cn() {
        return this.cq.mr(this.cs, this.bs, this.br);
    }
    ct() {
        return this.cq.ng(this.cs);
    }
    cu(a, b, c, d) {
        if (this.cq.nd) {
            let e = new GeometryGroup();
            this.cq.mv.lq(e, a, b, c, d);
        }
        else {
        }
    }
    cw() {
        if (this.cq.oj != null) {
            this.cq.oi = this.cq.oj;
        }
        else {
            this.cq.oi = this.cq.ku;
        }
    }
    cc(a) {
        this.cs.f(a);
    }
    a2(a, b) {
        if (a.d) {
            if (this.cq.m6 != 0 && !b) {
                let c = this.cr.g$j;
                c.ac = this.cq.nh;
                c._stroke = this.cq.oi;
                c.ad = this.cq.ol;
                c.ai = this.cq.ok;
                a.u(c);
            }
        }
        super.a2(a, b);
    }
    cx() {
        return Rect.empty;
    }
    getDefaultTooltipTemplate() {
        let a = "<div class='ui-chart-default-tooltip-content'><span>" + "${item." + this.cq.nn + "}" + "</span><br/><span";
        let b = this.e.a0.a$q(this.e);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.cq.fr + ": </span><span class='ui-priority-primary'>" + "${item." + this.cq.nt + "}</span></div>";
        return a;
    }
}
PolarBaseView.$t = markType(PolarBaseView, 'PolarBaseView', MarkerSeriesView.$);
