/*
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 * as tslib_1 from "tslib";
import { RadialBucketCalculator } from "./RadialBucketCalculator";
import { Type, markType, Point_$type, enumGetBox, typeCast } from "igniteui-react-core/ES5/type";
import { isNaN_, intDivide, isInfinity } from "igniteui-react-core/ES5/number";
import { RadialBase } from "./RadialBase";
import { CategoryLineRasterizer } from "./CategoryLineRasterizer";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { TrendLineType_$type } from "igniteui-react-core/ES5/TrendLineType";
import { Brush } from "igniteui-react-core/ES5/Brush";
import { PenLineCap_$type } from "igniteui-react-core/ES5/PenLineCap";
import { DoubleCollection } from "igniteui-react-core/ES5/DoubleCollection";
import { RadialFrame } from "./RadialFrame";
import { ScalerParams } from "./ScalerParams";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { AxisRange } from "./AxisRange";
import { NumericAxisBase } from "./NumericAxisBase";
import { IFastItemsSource_$type } from "igniteui-react-core/ES5/IFastItemsSource";
import { RadialBaseView } from "./RadialBaseView";
import { CollisionAvoider } from "./CollisionAvoider";
import { Clipper } from "igniteui-react-core/ES5/Clipper";
import { TrendResolutionParams } from "./TrendResolutionParams";
import { RadialTrendLineManager } from "./RadialTrendLineManager";
import { CategoryMarkerManager } from "./CategoryMarkerManager";
import { PropertyMetadata } from "igniteui-react-core/ES5/PropertyMetadata";
import { stringIsNullOrEmpty } from "igniteui-react-core/ES5/string";
var AnchoredRadialBucketCalculator = /** @class */ (function (_super) {
    tslib_1.__extends(AnchoredRadialBucketCalculator, _super);
    function AnchoredRadialBucketCalculator(a) {
        var _this = _super.call(this, a) || this;
        _this.f = null;
        _this.f = a;
        return _this;
    }
    AnchoredRadialBucketCalculator.prototype.getBucket = function (a) {
        var b = this.f.cs.nn;
        var c = Math.min(a * this.b, b.count - 1);
        var d = Math.min(c + this.b - 1, b.count - 1);
        var e = NaN;
        var f = NaN;
        for (var g = c; g <= d; ++g) {
            var 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.$);
    return AnchoredRadialBucketCalculator;
}(RadialBucketCalculator));
export { AnchoredRadialBucketCalculator };
var AnchoredRadialSeries = /** @class */ (function (_super) {
    tslib_1.__extends(AnchoredRadialSeries, _super);
    function AnchoredRadialSeries() {
        var _this = _super.call(this) || this;
        _this.ni = null;
        _this.nm = null;
        _this.og = { $type: Point_$type, x: 0, y: 0 };
        _this.nk = null;
        _this.nj = null;
        _this.nk = new RadialFrame(3);
        _this.ni = new CategoryLineRasterizer();
        return _this;
    }
    AnchoredRadialSeries.prototype.bf = function () {
        return new AnchoredRadialSeriesView(this);
    };
    AnchoredRadialSeries.prototype.hm = function () {
        _super.prototype.hm.call(this);
        this.mr = null;
        this.mt = null;
    };
    AnchoredRadialSeries.prototype.il = function (a) {
        _super.prototype.il.call(this, a);
        this.nh = a;
    };
    AnchoredRadialSeries.prototype.fa = function (a, b) {
        return this.fb(a, b, this.mr, null, this.nn);
    };
    AnchoredRadialSeries.prototype.e8 = function (a, b) {
        return this.e9(a, b, this.mr, null, this.nn);
    };
    AnchoredRadialSeries.prototype.d5 = function (a, b, c, d, e) {
        if (this.nn == null) {
            return Number.POSITIVE_INFINITY;
        }
        return this.d6(a, b, this.mr, d, e, this.nn.count, null);
    };
    AnchoredRadialSeries.prototype.ej = function (a, b, c) {
        var d = this.getEffectiveViewport1(this.bi);
        var e = this.ns(this.mr, this.bi.bs, this.bi.br, d);
        var f = new ScalerParams(0, this.bi.bs, this.bi.br, this.mr.b8, d);
        f.c = this.bs.m0;
        return this.el(this.nn, a, this.mr, f, e, null, b, c);
    };
    AnchoredRadialSeries.prototype.lc = function (a, b, c) {
        if (this.mt == null || this.mr == null || this.bi == null || this.bi.bs.isEmpty || this.bi.br.isEmpty) {
            return { $type: Point_$type, x: NaN, y: NaN };
        }
        var d = this.getEffectiveViewport1(this.bi);
        var e = new ScalerParams(0, this.bi.bs, this.bi.br, this.mt.b8, d);
        e.c = this.getEffectiveViewport1(this.bi);
        var f = this.ej(a, b, c);
        f = this.mt.dt(f, e);
        var g = this.mu.c(a);
        if (!b && this.mr != null) {
            var h = this.fa(a, c);
            var i = this.e8(a, c);
            var j = this.ns(this.mr, this.bi.bs, this.bi.br, d);
            var k = new ScalerParams(0, this.bi.bs, this.bi.br, this.mr.b8, d);
            k.c = this.bs.m0;
            var l = this.d5(a, h, this.mr, k, j);
            var m = this.d5(a, i, this.mr, k, j);
            if (m <= l) {
                g = this.mr.dt(i, k) + j;
            }
            else {
                g = this.mr.dt(h, k) + j;
            }
        }
        var n = this.mu.d(g, f, this.bi.bs, this.bi.br);
        var o = this.mu.e(g, f, this.bi.bs, this.bi.br);
        return { $type: Point_$type, x: n, y: o };
    };
    Object.defineProperty(AnchoredRadialSeries.prototype, "nn", {
        get: function () {
            return this.nm;
        },
        set: function (a) {
            if (this.nm != a) {
                var b = this.nm;
                this.nm = a;
                this.raisePropertyChanged("ValueColumn", b, this.nm);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredRadialSeries.prototype, "oc", {
        get: function () {
            return this.c(AnchoredRadialSeries.n3);
        },
        set: function (a) {
            this.h(AnchoredRadialSeries.n3, a);
        },
        enumerable: true,
        configurable: true
    });
    AnchoredRadialSeries.prototype.an = function (a) {
        if (a != null && a == this.mr && this.nn != null && this.nn.count > 0) {
            return new AxisRange(0, this.nn.count - 1);
        }
        if (a != null && a == this.mt && this.nn != null && this.nn.count > 0) {
            return new AxisRange(this.nn.minimum, this.nn.maximum);
        }
        return null;
    };
    AnchoredRadialSeries.prototype.ir = function (a, b, c, d) {
        _super.prototype.ir.call(this, a, b, c, d);
        if (this.nh.ct.g$b(a, b, c, d)) {
            this.i4(false);
            this.ib();
        }
        var e = typeCast(NumericAxisBase.$, this.mt);
        switch (b) {
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) !== null) {
                    c.deregisterColumn(this.nn);
                    this.nn = null;
                }
                if (typeCast(IFastItemsSource_$type, d) !== null) {
                    this.nn = this.bw(this.nz);
                    this.nh.co.e(this.eq);
                }
                if (e != null && !e.ck()) {
                    this.nh.co.e(this.eq);
                    this.i4(false);
                }
                break;
            case AnchoredRadialSeries.$$p[0]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.nn);
                    this.nn = this.bw(this.nz);
                }
                break;
            case "ValueColumn":
                if (e != null && !e.ck()) {
                    this.nh.co.e(this.eq);
                    this.i4(false);
                }
                break;
            case "TrendLineBrush":
                this.jf();
                break;
            case "TrendLineType":
                this.ib();
                break;
        }
    };
    AnchoredRadialSeries.prototype.hr = function (a, b, c, d) {
        switch (a) {
            case 4:
            case 1:
            case 0:
                this.nh.co.e(this.eq);
                break;
        }
        this.nh.ct.g$e(a, b, c, d);
        switch (a) {
            case 4:
                if (this.mt != null && !this.mt.ck()) {
                    this.i4(true);
                }
                break;
            case 1:
                if (this.mt != null && !this.mt.ck()) {
                    this.i4(true);
                }
                break;
            case 0:
                if (this.mt != null && !this.mt.ck()) {
                    this.i4(true);
                }
                break;
            case 2:
                if (this.nz != null && this.nh.co.b > 0 && this.mt != null && !this.mt.ck()) {
                    this.i4(true);
                }
                break;
            case 3:
                if (d == this.nz) {
                    if (this.mt != null && !this.mt.ck()) {
                        this.i4(true);
                    }
                }
                break;
        }
    };
    AnchoredRadialSeries.prototype.du = function (a, b, c) {
        var d = _super.prototype.du.call(this, a, b, c);
        var e = c;
        if (this.bz == null || this.bz.count == 0 || this.mr == null || this.nn == null || this.mr.jr == 0 || this.mt == null || isInfinity(this.mt.jx) || isInfinity(this.mt.jw) || e.co.b < 1) {
            d = false;
        }
        return d;
    };
    AnchoredRadialSeries.prototype.getOffsetValue = function () {
        return this.ns(this.mr, this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
    };
    AnchoredRadialSeries.prototype.getCategoryWidth = function () {
        return this.mr.getCategorySize(this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
    };
    AnchoredRadialSeries.prototype.get_nq = function () {
        return false;
    };
    Object.defineProperty(AnchoredRadialSeries.prototype, "nq", {
        get: function () {
            return this.get_nq();
        },
        enumerable: true,
        configurable: true
    });
    AnchoredRadialSeries.prototype.ns = function (a, b, c, d) {
        var e = 0;
        var 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.m6(), b, c, d);
                break;
        }
        if (a.b8) {
            e = -e;
        }
        return e;
    };
    AnchoredRadialSeries.prototype.nb = function (a, b) {
        var _this = this;
        var c = b.bs;
        var d = b.br;
        var e = this.getEffectiveViewport1(b);
        var f = this.mr;
        var g = this.mt;
        var h = g.jx;
        var i = g.jw;
        a.f.clear();
        a.m.clear();
        a.p.clear();
        var j = this.lu();
        var k = 0;
        var l = b;
        var m = new CollisionAvoider();
        var n = 0;
        var o = b.co.d;
        n = this.ns(f, c, d, e);
        l.ct.q = this.mt.lc;
        l.ct.p = this.mt.lb;
        l.ct.r = function (p, q) { return _this.nt(p, q, c, d); };
        l.ct.s = function (p, q) { return _this.nu(p, q, c, d); };
        var p = ((function () {
            var $ret = new Clipper(0, d, false);
            $ret.i = a.p;
            return $ret;
        })());
        var q = ((function () {
            var $ret = new TrendResolutionParams();
            $ret.c = b.co.b;
            $ret.d = b.co.c;
            $ret.e = o;
            $ret.a = n;
            $ret.b = _this.eq;
            $ret.f = d;
            $ret.g = c;
            return $ret;
        })());
        l.ct.t(a.p, this.nl, this.nn, this.nw, function (r) { return _this.mr.getScaledAngle(r); }, function (r) { return _this.mt.li(r); }, q, p);
        var r = true;
        if (this.nr(b)) {
            o--;
        }
        for (var s = b.co.c; s <= o; ++s) {
            var t = s;
            if (t * b.co.b >= this.mr.jr) {
                t -= intDivide((this.mr.jr), b.co.b);
            }
            var 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.li(u[1]);
                if (b.co.b > 1) {
                    if (u[2] < h || u[2] > i) {
                        continue;
                    }
                    u[2] = g.li(u[2]);
                }
                else {
                    u[2] = u[1];
                }
                if ((isNaN_(u[1]) || isNaN_(u[2])) && r && this.nq && this.np()) {
                    o++;
                }
                else {
                    r = false;
                }
                a.f.add(u);
                if (j) {
                    var v = Math.min(t * b.co.b, this.bz.count - 1);
                    var w = this.mu.d(u[0], u[1], c, d);
                    var x = this.mu.e(u[0], u[1], c, d);
                    var 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 });
                        var z = b.cp.item(k);
                        z.ak = v;
                        z.content.item = this.bz.item(v);
                        ++k;
                    }
                }
            }
            else {
                if (r && this.nq && this.np()) {
                    o++;
                }
            }
        }
        b.cp.count = k;
        return;
    };
    AnchoredRadialSeries.prototype.nt = function (a, b, c, d) {
        return this.mu.d(a, b, c, d);
    };
    AnchoredRadialSeries.prototype.nu = function (a, b, c, d) {
        return this.mu.e(a, b, c, d);
    };
    AnchoredRadialSeries.prototype.nr = function (a) {
        var b = a;
        return !this.nq && b.co.c == 0 && b.co.d == this.mr.jr;
    };
    AnchoredRadialSeries.prototype.ng = function (a, b, c) {
        var d = null;
        var e = c.bs;
        var f = c.br;
        if (b > -1 && !e.isEmpty && !f.isEmpty) {
            var g = a._inner[0][0] < f.left - 2000 ? f.left - 10 : NaN;
            var h = f.bottom + 10;
            var i = a._inner[b][0] > f.right + 2000 ? f.right + 10 : NaN;
            var j = f.top - 10;
            d = new Clipper(1, g, h, i, j, false);
        }
        return d;
    };
    AnchoredRadialSeries.prototype.n2 = function (a, b, c, d, e) {
        if (a.count > 0 && d.count > 0) {
            if (!e || this.no()) {
                a.add(this.og);
                a.add(a._inner[0]);
                d.add(this.og);
                d.add(d._inner[0]);
            }
        }
    };
    AnchoredRadialSeries.prototype.np = function () {
        return !this.no();
    };
    AnchoredRadialSeries.prototype.no = function () {
        var a = this.bi.bs;
        return !a.containsPoint({ $type: Point_$type, x: 0.5, y: 0.5 });
    };
    AnchoredRadialSeries.prototype.ho = function (a, b) {
        _super.prototype.ho.call(this, a, b);
        var c = b;
        if (a) {
            c.cp.clear();
        }
        c.ct.g$d();
    };
    AnchoredRadialSeries.prototype.nc = function (a, b) {
        var c = b.bs;
        var d = b.br;
        var e = this.getEffectiveViewport1(b);
        var f = this.lh(b);
        var g = b;
        g.ct.g$g(a.p);
        CategoryMarkerManager.b(this, a.m, g.cp, this.lw);
        g.cj();
        this.n1(d, c, e, f, g);
    };
    AnchoredRadialSeries.prototype.n1 = function (a, b, c, d, e) {
        e.cu(a, b, c, d);
    };
    AnchoredRadialSeries.prototype.jf = function () {
        _super.prototype.jf.call(this);
        if (this.fd < 0) {
            return;
        }
        this.nh.cv();
    };
    AnchoredRadialSeries.prototype.fp = function (a, b) {
        if (a == this.nh.ct.g$j) {
            return null;
        }
        return _super.prototype.fp.call(this, a, b);
    };
    AnchoredRadialSeries.prototype.c7 = function (a) {
        var b = this.bi.bs;
        b = b.copy();
        var c = this.bi.br;
        var d = !b.isEmpty && !c.isEmpty && this.bz != null ? this.bz.indexOf(a) : -1;
        if (this.mr == null || this.nn == null || this.mt == null) {
            return false;
        }
        if (d < 0 || d > this.nn.count - 1) {
            return false;
        }
        var e = this.mr.getScaledAngle(d);
        var f = this.mt.li(this.nn.item(d));
        if (isNaN_(f)) {
            f = (this.mt.lb + this.mt.lc) / 2;
        }
        var g = 0.5 + (Math.cos(e) * f);
        var 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;
    };
    AnchoredRadialSeries.prototype.i6 = function (a, b) {
        _super.prototype.i6.call(this, a, b);
        if (!this.dj) {
            this.bi.az(b);
            return;
        }
        this.bi.az(b);
        var c = typeCast(AnchoredRadialSeriesView.$, this.bh);
        c.co.e(this.eq);
        if (this.cc(this.bh)) {
            return;
        }
        if (!this.dd) {
            this.nk = new RadialFrame(3);
            this.nb(this.nk, c);
        }
        this.dd = false;
        this.nc(this.nk, c);
        this.dj = false;
    };
    AnchoredRadialSeries.prototype.i3 = function (a, b, c, d, e) {
        _super.prototype.i3.call(this, a, b, c, d, e);
        var f = this.a0.a$h.item(d);
        var g = f;
        g.co.e(this.eq);
        f.ay(c);
        if (this.cc(g)) {
            return;
        }
        if (this.nj == null) {
            this.nj = new RadialFrame(3);
        }
        this.nj.u();
        this.nb(this.nj, g);
        this.nc(this.nj, g);
    };
    AnchoredRadialSeries.prototype.hx = function (a) {
        _super.prototype.hx.call(this, a);
        this.a2.exportTrendlineData(this, a, this.nh.ct.g$j);
    };
    AnchoredRadialSeries.$t = markType(AnchoredRadialSeries, 'AnchoredRadialSeries', RadialBase.$);
    AnchoredRadialSeries.n3 = DependencyProperty.i("ActualTrendLineBrush", Brush.$, AnchoredRadialSeries.$, new PropertyMetadata(2, null, function (a, b) { return a.raisePropertyChanged("ActualTrendLineBrush", b.oldValue, b.newValue); }));
    return AnchoredRadialSeries;
}(RadialBase));
export { AnchoredRadialSeries };
Type.dep(DependencyProperty, PropertyMetadata, AnchoredRadialSeries, 'raisePropertyChanged', ['ValueMemberPath:nz:ob', [2, null], 'TrendLineType:nl:n9', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness:nv:n8', [1, 1.5], 'TrendLinePeriod:nw:n7', [1, 7], 'TrendLineZIndex:nx:oa', [1, 1], 'TrendLineBrush:od:n4', [Brush.$, null], 'TrendLineDashArray:oe:n5', [DoubleCollection.$], 'TrendLineDashCap:of:n6', [PenLineCap_$type, enumGetBox(PenLineCap_$type, 0)]]);
var AnchoredRadialSeriesView = /** @class */ (function (_super) {
    tslib_1.__extends(AnchoredRadialSeriesView, _super);
    function AnchoredRadialSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.cs = null;
        _this.ct = null;
        _this.co = new AnchoredRadialBucketCalculator(_this);
        _this.cs = a;
        _this.ct = new RadialTrendLineManager();
        return _this;
    }
    AnchoredRadialSeriesView.prototype.cu = function (a, b, c, d) {
    };
    AnchoredRadialSeriesView.prototype.cv = function () {
        this.cs.oc = null;
        if (this.cs.od != null) {
            this.cs.oc = this.cs.od;
        }
        else {
            this.cs.oc = this.cs.ku;
        }
    };
    AnchoredRadialSeriesView.prototype.a2 = function (a, b) {
        if (a.d) {
            if (!b) {
            }
            if (this.cs.nl != 0 && !b) {
                var c = this.ct.g$j;
                c.ac = this.cs.nv;
                c._stroke = this.cs.oc;
                c.ai = this.cs.oe;
                c.ad = this.cs.of;
                a.u(c);
            }
        }
        _super.prototype.a2.call(this, a, b);
    };
    AnchoredRadialSeriesView.prototype.getDefaultTooltipTemplate = function () {
        var a = "<div class='ui-chart-default-tooltip-content'>";
        if (this.cs.mr.e2 != null) {
            a += "<span>${item." + this.cs.mr.e2 + "}</span><br/>";
        }
        a += "<span";
        var b = this.e.a0.a$q(this.e);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.cs.fr + ": </span><span class='ui-priority-primary'>" + "${item." + this.cs.nz + "}</span></div>";
        return a;
    };
    AnchoredRadialSeriesView.$t = markType(AnchoredRadialSeriesView, 'AnchoredRadialSeriesView', RadialBaseView.$);
    return AnchoredRadialSeriesView;
}(RadialBaseView));
export { AnchoredRadialSeriesView };
