/*
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";
/**
 * @hidden
 */
export class PolarBase extends MarkerSeries {
    constructor() {
        super();
        this.m1 = null;
        this.mu = null;
        this.mz = null;
        this.or = null;
        this.oq = null;
        this.m7 = null;
        this.m9 = null;
        this.na = null;
        this.m4 = new PolarFrame();
        this.m6 = new PolarFrame();
        this.m3 = new PolarFrame();
        this.my = null;
        this.m5 = null;
        this.m2 = null;
        this.m5 = new PolarFrame();
        this.m6.x = runOn(this, this.op);
        this.m4.x = runOn(this, this.op);
        this.m3.x = runOn(this, this.op);
        this.m7 = new SeriesRenderer$2(PolarFrame.$, PolarBaseView.$, 0, runOn(this, this.n2), runOn(this, this.n4), runOn(this, this.ca), runOn(this, this.je), runOn(this, this.n0));
    }
    bf() {
        return new PolarBaseView(this);
    }
    im(a) {
        super.im(a);
        this.m0 = a;
    }
    hn() {
        super.hn();
        this.mw = null;
        this.mx = null;
    }
    get_c0() {
        return true;
    }
    ng(a) {
        if (!this.hasMarkers) {
            return false;
        }
        let b = this.mw;
        let c = new ScalerParams(1, this.bs.mq, this.lr, b.b8);
        c.c = this.getEffectiveViewport1(this.bi);
        let d = this.mx;
        let e = new ScalerParams(1, this.bs.mq, this.lr, d.b8);
        e.c = this.getEffectiveViewport1(this.bi);
        a.clear();
        this.lt.cc((f) => {
            if (f._visibility == 0) {
                let g = new SeriesPointOfInterest();
                let h = f.n;
                let i = f.o;
                if (h < this.lr.left || h > this.lr.right || i < this.lr.top || i > this.lr.bottom) {
                    return;
                }
                g.b = b.dw(h, c);
                g.c = d.dw(i, e);
                g.a = f.content;
                a.add(g);
            }
        });
        return true;
    }
    n0() {
        if (this.bt.g) {
            this.bt.t();
        }
    }
    n1() {
        this.my.e(this.m1.w, this.nb, this.nc, this.or, this.oq, (a, b) => Math.cos(b), (a, b) => Math.sin(b), true);
    }
    get nb() {
        return this.m9;
    }
    set nb(a) {
        if (this.m9 != a) {
            let b = this.nb;
            this.m9 = a;
            this.raisePropertyChanged("AngleColumn", b, this.nb);
        }
    }
    get nc() {
        return this.na;
    }
    set nc(a) {
        if (this.na != a) {
            let b = this.nc;
            this.na = a;
            this.raisePropertyChanged("RadiusColumn", b, this.nc);
        }
    }
    get ok() {
        return this.c(PolarBase.n5);
    }
    set ok(a) {
        this.h(PolarBase.n5, a);
    }
    h4() {
        super.h4();
        if (this.mx != null) {
            this.mx.g0(false);
        }
        if (this.mw != null) {
            this.mw.g0(false);
        }
    }
    hs(a, b, c, d) {
        let e = false;
        this.m0.cr.g$e(a, b, c, d);
        if (this.mw != null && !this.mw.ck()) {
            e = true;
        }
        if (this.mx != null && !this.mx.ck()) {
            e = true;
        }
        if (e) {
            this.i6(true);
        }
    }
    jl(a, b) {
        this.i6(false);
    }
    jm(a, b) {
        this.i6(false);
    }
    dv(a, b, c) {
        let d = true;
        if (!super.dv(a, b, c) || !c.l() || b.isEmpty || a.isEmpty || this.mw == null || this.mx == null || this.nb == null || this.nc == null || this.nb.count == 0 || this.nc.count == 0 || this.bz == null || this.bz.count != this.nb.count || this.bz.count != this.nc.count || this.my == null || this.mw.bf == null || this.mx.bf == null || this.mw.jx == this.mw.jw || this.mx.jx == this.mx.jw) {
            d = false;
        }
        return d;
    }
    i7(a) {
        let b;
        let c;
        let d = this.getViewInfo(c, b);
        c = d.p0;
        b = d.p1;
        if (!this.dv(c, b, this.bi)) {
            this.hp(true, this.bi);
            return;
        }
        this.or = b;
        this.oq = c;
        this.mz = new PolarAxisInfoCache(this.mw, this.mx, this.bz);
        let e = new SeriesRenderingArguments(this, c, b, a, this.dd);
        let f = this.m7.g(e, this.m4, this.m3, this.m6, this.m0);
        this.m4 = f.p1;
        this.m3 = f.p2;
        this.m6 = f.p3;
    }
    op(a) {
        let b = this.my.h(a.x, a.y, this.or, this.oq, this.mz.e, this.mz.d, this.mz.g, this.mz.f, this.mz.i, this.mz.h);
        return b;
    }
    an(a) {
        if (a != null && a == this.mw && this.nb != null) {
            return new AxisRange(this.nb.minimum, this.nb.maximum);
        }
        if (a != null && a == this.mx && this.nc != null) {
            return new AxisRange(this.nc.minimum, this.nc.maximum);
        }
        return null;
    }
    c8(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.mw == null || this.nb == null || this.mx == null || this.nc == null) {
            return false;
        }
        if (d < 0 || d > this.nb.count - 1 || d > this.nc.count - 1) {
            return false;
        }
        let e = this.mw.getScaledAngle(this.nb.item(d));
        let f = this.mx.li(this.nc.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;
    }
    fm(a) {
        return null;
    }
    e5(a) {
        return -1;
    }
    ag() {
        return [this.mw, this.mx];
    }
    is(a, b, c, d) {
        super.is(a, b, c, d);
        if (this.m0.cr.g$b(a, b, c, d)) {
            this.i6(false);
            this.ic();
        }
        switch (b) {
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.nb);
                    c.deregisterColumn(this.nc);
                    this.nb = null;
                    this.nc = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.nb = this.bw(this.np);
                    this.nc = this.bw(this.nv);
                }
                if ((this.mx != null && !this.mx.ck()) || (this.mw != null && !this.mw.ck())) {
                    this.i6(false);
                }
                break;
            case PolarBase.$$p[0]:
                if (this.mw != null && this.mx != null) {
                    this.my = new PolarAxes(this.mx, this.mw);
                }
                if (c != null) {
                    c.bv(this);
                }
                if (d != null) {
                    d.ch(this);
                }
                if (this.mw != null && !this.mw.ck()) {
                    this.i6(false);
                }
                else if (c != null && d == null) {
                    this.hp(true, this.bi);
                }
                break;
            case PolarBase.$$p[4]:
                if (this.mw != null && this.mx != null) {
                    this.my = new PolarAxes(this.mx, this.mw);
                }
                if (c != null) {
                    c.bv(this);
                }
                if (d != null) {
                    d.ch(this);
                }
                if (this.mx != null && !this.mx.ck()) {
                    this.i6(false);
                }
                else if (c != null && d == null) {
                    this.hp(true, this.bi);
                }
                if (this.mw != null && !this.mw.ck()) {
                    this.mw.gw();
                }
                break;
            case PolarBase.$$p[1]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nb);
                    this.nb = this.bw(this.np);
                }
                break;
            case "AngleColumn":
                this.m0.cr.g$i();
                if (this.mw != null && !this.mw.ck()) {
                    this.i6(false);
                }
                break;
            case PolarBase.$$p[5]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nc);
                    this.nc = this.bw(this.nv);
                }
                break;
            case "RadiusColumn":
                this.m0.cr.g$i();
                if (this.mx != null && !this.mx.ck()) {
                    this.i6(false);
                }
                break;
            case PolarBase.$$p[6]:
                this.i6(false);
                this.ic();
                break;
            case PolarBase.$$p[3]:
                this.i6(false);
                this.ic();
                break;
            case "TransitionProgress":
                this.mz = new PolarAxisInfoCache(this.mw, this.mx, this.bz);
                this.or = this.bi.bs;
                this.oq = this.bi.br;
                this.m6.v = this.nh;
                this.m6.c(this.ew, this.m4, this.m3);
                if (this.cc(this.bi)) {
                    return;
                }
                if (this.ew == 1) {
                    this.n4(this.m3, this.m0);
                }
                else {
                    this.n4(this.m6, this.m0);
                }
                if (this.bs != null) {
                    this.bs.jj(this);
                }
                break;
            case "TrendLineBrush":
                this.jh();
                break;
            case PolarBase.$$p[2]:
                this.i6(false);
                this.ic();
                break;
            case "TrendLineType":
                this.ic();
                break;
        }
    }
    ne(a) {
        if (typeCast(NumericRadiusAxis.$, a) !== null) {
            return true;
        }
        return false;
    }
    nd(a) {
        if (typeCast(NumericAngleAxis.$, a) !== null) {
            return true;
        }
        return false;
    }
    hp(a, b) {
        super.hp(a, b);
        let c = b;
        if (a) {
            c.cs.clear();
        }
        c.cr.g$d();
    }
    mv(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;
    }
    nz(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.nb.item(f), y: this.nc.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;
                })()));
            }
        }
    }
    n2(a, b) {
        let c = b.bs;
        let d = b.br;
        a.j.clear();
        a.n.clear();
        let e = Math.min(this.nb != null ? this.nb.count : 0, this.nc != null ? this.nc.count : 0);
        if (e < 1) {
            return;
        }
        this.mz = new PolarAxisInfoCache(this.mw, this.mx, this.bz);
        this.m1 = a;
        this.oq = d;
        this.or = c;
        b.cp.l(a.j, this.nk, c, d, this.er);
        if (e <= this.nk) {
            this.nz(a, e, c, d);
        }
        let f = this.mv(d, a.n);
        let g = Math.min(this.mw.jx, this.mw.jw);
        let h = Math.max(this.mw.jw, this.mw.jx);
        b.cr.q = this.nh;
        b.cr.p = 0;
        b.cr.s = this.mx.lc;
        b.cr.r = this.mx.lb;
        b.cr.t = (i, j) => this.my.c(i, j, c, d, Math.cos);
        b.cr.u = (i, j) => this.my.d(i, j, c, d, Math.sin);
        let i = new List$1(Number_$type, 0);
        for (let j = 0; j < this.nb.count; j++) {
            if (this.nb.item(j) >= g && this.nb.item(j) <= h) {
                i.add(this.nb.item(j));
            }
        }
        let k = this.nc;
        if (i.count != this.nb.count) {
            k = new List$1(Number_$type, 0);
            for (let l = 0; l < this.nb.count; l++) {
                if (this.nb.item(l) >= g && this.nb.item(l) <= h) {
                    k.add(this.nc.item(l));
                }
            }
        }
        b.cr.v(a.n, this.m8, i, k, this.nl, runOn(this.mw, this.mw.getScaledAngle), runOn(this.mx, this.mx.li), ((() => {
            let $ret = new TrendResolutionParams();
            $ret.b = this.er;
            $ret.f = d;
            $ret.g = c;
            return $ret;
        })()), f, g, h);
    }
    n4(a, b) {
        let c = b.bs;
        let d = b.br;
        let e = this.getEffectiveViewport1(b);
        let f = this.lj(b);
        this.mz = new PolarAxisInfoCache(this.mw, this.mx, this.bz);
        b.cp.j(a.j, this.ly);
        b.cj();
        let g = this.mv(d, b.cr.g$j.aj);
        b.cr.g$h(a.n, g);
        this.ny(d, c, e, f, b);
    }
    ny(a, b, c, d, e) {
        e.cu(a, b, c, d);
    }
    jh() {
        super.jh();
        if (this.fe < 0) {
            return;
        }
        this.m0.cw();
    }
    i8(a, b) {
        super.i8(a, b);
        if (!this.dk) {
            this.bi.az(b);
            return;
        }
        this.bi.az(b);
        if (this.cc(this.bh)) {
            return;
        }
        let c = this.bh;
        if (!this.de) {
            this.m5 = new PolarFrame();
            this.n2(this.m5, c);
        }
        this.de = false;
        this.n4(this.m5, c);
        this.dk = false;
    }
    i5(a, b, c, d, e) {
        super.i5(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.m2 == null) {
            this.m2 = new PolarFrame();
        }
        this.n2(this.m2, g);
        this.n4(this.m2, g);
    }
    n3(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);
        }
    }
    mt(a, b, c) {
        this.n1();
        return this.m1.w.toArray();
    }
    ni(a) {
        let b = new List$1(Number_$type, 0);
        let c = this.bz;
        for (let d of fromEnum(this.m0.cs.c)) {
            b.add(c.indexOf(d));
        }
        return b;
    }
    oo(a) {
        return { $type: Point_$type, x: this.nb.item(a), y: this.nc.item(a) };
    }
    hy(a) {
        super.hy(a);
        this.a2.exportTrendlineData(this, a, this.m0.cr.g$j);
    }
}
PolarBase.$t = markType(PolarBase, 'PolarBase', MarkerSeries.$);
PolarBase.n5 = 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:mw:n6', [NumericAngleAxis.$, null], 'AngleMemberPath:np:n7', [2], 'ClipSeriesToBounds:nf:n8', [0, false], 'MaximumMarkers:nk:n9', [1, 400], 'RadiusAxis:mx:oa', [NumericRadiusAxis.$, null], 'RadiusMemberPath:nv:ob', [2], 'UseCartesianInterpolation:nh:oj', [0, true], 'TrendLineType:m8:oh', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness:nj:og', [1, 1.5], 'TrendLinePeriod:nl:of', [1, 7], 'TrendLineZIndex:nm:oi', [1, 1], 'TrendLineBrush:ol:oc', [Brush.$, null], 'TrendLineDashArray:om:od', [DoubleCollection.$], 'TrendLineDashCap:on:oe', [PenLineCap_$type, enumGetBox(PenLineCap_$type, 0)]]);
/**
 * @hidden
 */
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.nk = 1000;
            this.by.lu = 2;
        }
    }
    co() {
        let a = new NumericMarkerManager(0, (b) => this.cs.item(b), (b) => this.cq.mz.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.oo);
        return a;
    }
    cv(a) {
        this.cq.n3(a, this.cs);
    }
    cn() {
        return this.cq.mt(this.cs, this.bs, this.br);
    }
    ct() {
        return this.cq.ni(this.cs);
    }
    cu(a, b, c, d) {
        if (this.cq.nf) {
            let e = new GeometryGroup();
            this.cq.mx.lq(e, a, b, c, d);
        }
        else {
        }
    }
    cw() {
        if (this.cq.ol != null) {
            this.cq.ok = this.cq.ol;
        }
        else {
            this.cq.ok = this.cq.kw;
        }
    }
    cc(a) {
        this.cs.f(a);
    }
    a2(a, b) {
        if (a.d) {
            if (this.cq.m8 != 0 && !b) {
                let c = this.cr.g$j;
                c.ac = this.cq.nj;
                c._stroke = this.cq.ok;
                c.ad = this.cq.on;
                c.ai = this.cq.om;
                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.np + "}" + "</span><br/><span";
        let b = this.e.a0.a$q(this.e);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.cq.fs + ": </span><span class='ui-priority-primary'>" + "${item." + this.cq.nv + "}</span></div>";
        return a;
    }
}
PolarBaseView.$t = markType(PolarBaseView, 'PolarBaseView', MarkerSeriesView.$);
