/*
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 { __extends, __values } from "tslib";
import { AnchoredRadialSeries } from "./AnchoredRadialSeries";
import { DependencyProperty } from "igniteui-react-core";
import { Defaults } from "./Defaults";
import { Point_$type, runOn, markType, markDep, fromEnum } from "igniteui-react-core";
import { Pool$1 } from "igniteui-react-core";
import { Path } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { PathGeometry } from "igniteui-react-core";
import { ViewportUtils } from "./ViewportUtils";
import { SliceCoords } from "./SliceCoords";
import { PathFigure } from "igniteui-react-core";
import { LineSegment } from "igniteui-react-core";
import { ArcSegment } from "igniteui-react-core";
import { PieSliceCollisionGeometry } from "igniteui-react-core";
import { Size } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { intDivide, isNaN_ } from "igniteui-react-core";
import { AnchoredRadialSeriesView } from "./AnchoredRadialSeriesView";
import { DataContext } from "igniteui-react-core";
/**
 * @hidden
 */
var RadialPieSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(RadialPieSeries, _super);
    function RadialPieSeries() {
        var _this = _super.call(this) || this;
        _this.ab = RadialPieSeries.$;
        return _this;
    }
    RadialPieSeries.prototype.bi = function () {
        return new RadialPieSeries();
    };
    RadialPieSeries.prototype.get_fl = function () {
        return true;
    };
    RadialPieSeries.prototype.get_fj = function () {
        return true;
    };
    RadialPieSeries.prototype.ji = function () {
        if (!isNaN_(this.jh)) {
            return _super.prototype.ji.call(this);
        }
        return Defaults.h;
    };
    RadialPieSeries.prototype.cq = function () {
        return new RadialPieSeriesView(this);
    };
    RadialPieSeries.prototype.qw = function (a) {
        _super.prototype.qw.call(this, a);
        this.adc = a;
    };
    RadialPieSeries.prototype.preferredCategoryMode = function (a) {
        return a != null && a == this.yq ? 2 : 0;
    };
    RadialPieSeries.prototype.o2 = function (a, b) {
        _super.prototype.o2.call(this, a, b);
        var c = b;
        if (a && c.c6 != null) {
            c.c6.count = 0;
        }
    };
    RadialPieSeries.prototype.iu = function () {
        return this.yq.k5(this.ct.by, this.ct.bx, this.getEffectiveViewport1(this.ct));
    };
    RadialPieSeries.prototype.aq = function (a, b) {
        var c = new List$1(Rect.$, 0);
        var d = this.ct.by;
        var e = this.ct.bx;
        var f = this.getEffectiveViewport1(this.ct);
        var g = this.wc(this.ct);
        var h = this.yv.k2(e, d, f, g);
        var i = { $type: Point_$type, x: 0.5, y: 0.5 };
        var j = this.yv;
        var k = Math.max(0, 0.5 * j.no);
        var l = k;
        l = Math.max(l, h.minLength);
        var m = this.yq.k5(d, e, f);
        var n = this.yq != null && this.yq.cl;
        var o = this.y0;
        if (this.d1()) {
            o = this.y3;
        }
        {
            if (n) {
                m = this.zq(a, d, e, f);
            }
            if (b < 0 || b > o.f.count - 1) {
                return null;
            }
            var p = o.f._inner[b][0];
            var q = Math.min(o.f._inner[b][2], h.maxLength);
            return this.add(d, e, f, p - (m * 0.5), p + (m * 0.5), l, q, i);
        }
    };
    RadialPieSeries.prototype.get_eb = function () {
        return true;
    };
    RadialPieSeries.prototype.get_ab4 = function () {
        return true;
    };
    RadialPieSeries.prototype.get_aby = function () {
        return true;
    };
    RadialPieSeries.prototype.aa1 = function (a, b) {
        _super.prototype.aa1.call(this, a, b);
        var c = b;
        var d = b.by;
        var e = b.bx;
        var f = this.getEffectiveViewport1(b);
        var g = this.wc(b);
        var h = this.yv.k2(e, d, f, g);
        var i = a.f;
        var j = this.yv;
        var k = Math.max(0, 0.5 * j.no);
        var l = k;
        l = Math.max(l, h.minLength);
        var m = this.yq.k5(d, e, f);
        var n = this.yq.cl;
        var o = { $type: Point_$type, x: 0.5, y: 0.5 };
        var p = this.ade;
        var q = this.adf;
        var r = (p > 0 && q > 0);
        var s = this.abw.count;
        this.y6.a2(this, this.zn(), runOn(this, this.ye), this.zw(b), this.zx(b));
        this.y6.r = this.ade;
        this.y6.s = this.adf;
        this.y6.k = this.ade;
        this.y6.l = this.adf;
        var t = false;
        var u = this.y6.b;
        if (u != null) {
            t = true;
        }
        var v = this.yq;
        var w = new ScalerParams(1, b.by, b.bx, v.ch);
        w.c = this.getEffectiveViewport();
        var x = 0;
        var y = 0;
        for (var z = 0; z < i.count; ++z) {
            var aa = i._inner[z][0];
            var ab = Math.min(i._inner[z][2], h.maxLength);
            var ac = i._inner[z][1];
            var ad = i._inner[z][2];
            var ae = i._inner[z][3];
            if (t) {
                this.acs(i, z, s, v, w, b.q);
            }
            if (n) {
                if (isNaN_(aa) || isNaN_(ac) || isNaN_(ad)) {
                    continue;
                }
                var af = (b.cx.c + z) * b.cx.b;
                if ((b.cx.c + z) * b.cx.b > this.yq.lh - 1) {
                    if ((af) * b.cx.b >= this.yq.lg) {
                        af = (af) - (intDivide((this.yq.lg), b.cx.b));
                    }
                }
                m = ae;
                if (isNaN_(m)) {
                    continue;
                }
            }
            var ag = c.c6.item(x);
            x++;
            var ah = this.y6.k;
            var ai = this.y6.l;
            r = (ah > 0 && ai > 0);
            var aj = null;
            if (r) {
                aj = this.adk(d, e, f, aa - (m * 0.5), aa + (m * 0.5), l, ab, o, ah, ai);
            }
            else {
                aj = this.adl(d, e, f, aa - (m * 0.5), aa + (m * 0.5), l, ab, o);
            }
            ag.an = aj;
            this.y6.ad(ag, false, false, false, false);
            var ak = i._inner[z][2];
            if (ak > y) {
                y = ak;
            }
        }
        c.cz = ViewportUtils.f(y, d, e);
        c.c0 = { $type: Point_$type, x: ViewportUtils.e(o.x, d, e, f), y: ViewportUtils.i(o.y, d, e, f) };
        c.c6.count = x;
        c.db();
    };
    RadialPieSeries.prototype.adl = function (a, b, c, d, e, f, g, h) {
        var i = SliceCoords.b(a, b, c, d, e, f, g, h);
        var j = new PathFigure();
        j._startPoint = i.d;
        j._isClosed = true;
        j._segments.add(((function () {
            var $ret = new LineSegment(1);
            $ret.c = i.f;
            return $ret;
        })()));
        j._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = i.h;
            $ret.f = i.n;
            $ret.d = 1;
            $ret.b = i.c;
            return $ret;
        })()));
        j._segments.add(((function () {
            var $ret = new LineSegment(1);
            $ret.c = i.j;
            return $ret;
        })()));
        j._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = i.d;
            $ret.f = i.m;
            $ret.d = 0;
            $ret.b = i.c;
            return $ret;
        })()));
        var k = new PathGeometry();
        k.c.add(j);
        return k;
    };
    RadialPieSeries.prototype.add = function (a, b, c, d, e, f, g, h) {
        var i = SliceCoords.b(a, b, c, d, e, f, g, h);
        if (isNaN_(i.n.width) || isNaN_(d) || isNaN_(e)) {
            return null;
        }
        var j = ViewportUtils.e(0.5, a, b, c);
        var k = ViewportUtils.i(0.5, a, b, c);
        return new PieSliceCollisionGeometry(j, k, i.n.width, i.m.width, d, e);
    };
    RadialPieSeries.prototype.adk = function (a, b, c, d, e, f, g, h, i, j) {
        var k = SliceCoords.a(a, b, c, d, e, f, g, h, i, j);
        if (k == null) {
            return this.adl(a, b, c, d, e, f, g, h);
        }
        var l = new PathFigure();
        l._startPoint = k.d;
        l._isClosed = true;
        var m = ((d + ((e - d) * 0.5)) * 180 / Math.PI) + 90;
        var n = new Size(1, k.l.width * (f / g), k.l.height * (f / g));
        l._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = k.e;
            $ret.f = n;
            $ret.c = m;
            $ret.d = 1;
            $ret.b = false;
            return $ret;
        })()));
        l._segments.add(((function () {
            var $ret = new LineSegment(1);
            $ret.c = k.f;
            return $ret;
        })()));
        l._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = k.g;
            $ret.f = k.l;
            $ret.c = m;
            $ret.d = 1;
            $ret.b = false;
            return $ret;
        })()));
        l._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = k.h;
            $ret.f = k.n;
            $ret.d = 1;
            $ret.b = k.c;
            return $ret;
        })()));
        l._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = k.i;
            $ret.f = k.l;
            $ret.c = m;
            $ret.d = 1;
            $ret.b = false;
            return $ret;
        })()));
        l._segments.add(((function () {
            var $ret = new LineSegment(1);
            $ret.c = k.j;
            return $ret;
        })()));
        l._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = k.k;
            $ret.f = n;
            $ret.c = m;
            $ret.d = 1;
            $ret.b = false;
            return $ret;
        })()));
        l._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = k.d;
            $ret.f = k.m;
            $ret.d = 0;
            $ret.b = k.c;
            return $ret;
        })()));
        var o = new PathGeometry();
        o.c.add(l);
        return o;
    };
    RadialPieSeries.prototype.q4 = function (a, b, c, d) {
        _super.prototype.q4.call(this, a, b, c, d);
        switch (b) {
            case RadialPieSeries.$$p[0]:
            case RadialPieSeries.$$p[1]:
                this.qy();
                break;
        }
    };
    RadialPieSeries.$t = markType(RadialPieSeries, 'RadialPieSeries', AnchoredRadialSeries.$);
    RadialPieSeries.$$p = markDep(DependencyProperty, PropertyMetadata, RadialPieSeries, 'raisePropertyChanged', ['RadiusX:ade:adi', [1, 2], 'RadiusY:adf:adj', [1, 2]]);
    return RadialPieSeries;
}(AnchoredRadialSeries));
export { RadialPieSeries };
/**
 * @hidden
 */
var RadialPieSeriesView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(RadialPieSeriesView, _super);
    function RadialPieSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.c5 = null;
        _this.c6 = null;
        _this.c7 = null;
        _this.dc = new Path();
        _this.c5 = a;
        _this.c6 = ((function () {
            var $ret = new Pool$1(Path.$);
            $ret.create = runOn(_this, _this.dd);
            $ret.activate = runOn(_this, _this.c8);
            $ret.disactivate = runOn(_this, _this.da);
            $ret.destroy = runOn(_this, _this.c9);
            return $ret;
        })());
        return _this;
    }
    RadialPieSeriesView.prototype.au = function () {
        _super.prototype.au.call(this);
        this.c7 = new List$1(Path.$, 0);
        if (!this.q) {
            this.cw.w1 = Defaults.c;
            this.cw.jn = Defaults.i;
        }
    };
    RadialPieSeriesView.prototype.dd = function () {
        var _this = this;
        var a = ((function () {
            var $ret = new Path();
            $ret.dataContext = ((function () {
                var $ret = new DataContext();
                $ret.series = _this.e;
                return $ret;
            })());
            return $ret;
        })());
        this.c7.add(a);
        a._visibility = 1;
        return a;
    };
    RadialPieSeriesView.prototype.c8 = function (a) {
        a._visibility = 0;
    };
    RadialPieSeriesView.prototype.da = function (a) {
        a._visibility = 1;
    };
    RadialPieSeriesView.prototype.c9 = function (a) {
        this.c7.remove(a);
    };
    RadialPieSeriesView.prototype.bg = function (a, b) {
        _super.prototype.bg.call(this, a, b);
        var c = a;
    };
    RadialPieSeriesView.prototype.ac = function (a) {
        return this.c7._inner[a];
    };
    RadialPieSeriesView.prototype.ab = function (a) {
        var b = this.c7._inner[a];
        this.dc._visibility = b._visibility;
        this.dc.an = b.an;
        var c = this.bs(a);
        this.dc._fill = c;
        this.dc._stroke = c;
        this.dc.ad = this.e.ic;
        return this.dc;
    };
    RadialPieSeriesView.prototype.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        if (a.d) {
            for (var c = 0; c < this.c7.count; c++) {
                var d = this.aa(c, b);
                a.t(d);
            }
        }
    };
    RadialPieSeriesView.prototype.db = function () {
        this.as();
    };
    RadialPieSeriesView.prototype.an = function (a) {
        var e_1, _a;
        _super.prototype.an.call(this, a);
        var b = 0;
        try {
            for (var _b = __values(fromEnum(this.c6.a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var c = _c.value;
                this.e.bb.exportPathData(a, c, "slice" + b, ["Main", "Fill"]);
                b++;
            }
        }
        catch (e_1_1) {
            e_1 = { error: e_1_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_1)
                    throw e_1.error;
            }
        }
    };
    RadialPieSeriesView.$t = markType(RadialPieSeriesView, 'RadialPieSeriesView', AnchoredRadialSeriesView.$);
    return RadialPieSeriesView;
}(AnchoredRadialSeriesView));
export { RadialPieSeriesView };
