/*
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 { 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 { Size } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { 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.get_e0 = function () {
        return true;
    };
    RadialPieSeries.prototype.get_ey = function () {
        return true;
    };
    RadialPieSeries.prototype.ip = function () {
        if (!isNaN_(this.io)) {
            return _super.prototype.ip.call(this);
        }
        return Defaults.h;
    };
    RadialPieSeries.prototype.cg = function () {
        return new RadialPieSeriesView(this);
    };
    RadialPieSeries.prototype.o0 = function (a) {
        _super.prototype.o0.call(this, a);
        this.x9 = a;
    };
    RadialPieSeries.prototype.preferredCategoryMode = function (a) {
        return a != null && a == this.vi ? 2 : 0;
    };
    RadialPieSeries.prototype.nj = function (a, b) {
        _super.prototype.nj.call(this, a, b);
        var c = b;
        if (a && c.c4 != null) {
            c.c4.count = 0;
        }
    };
    RadialPieSeries.prototype.h0 = function () {
        return this.vi.k4(this.cj.by, this.cj.bx, this.getEffectiveViewport1(this.cj));
    };
    RadialPieSeries.prototype.get_du = function () {
        return true;
    };
    RadialPieSeries.prototype.wo = function (a, b) {
        _super.prototype.wo.call(this, a, b);
        var c = b;
        var d = b.by;
        var e = b.bx;
        var f = this.getEffectiveViewport1(b);
        var g = this.to(b);
        var h = this.vp.k1(e, d, f, g);
        var i = a.f;
        var j = this.vp;
        var k = Math.max(0, 0.5 * j.nn);
        var l = k;
        l = Math.max(l, h.minLength);
        var m = this.vi.k4(d, e, f);
        var n = { $type: Point_$type, x: 0.5, y: 0.5 };
        var o = this.ya;
        var p = this.yb;
        var q = (o > 0 && p > 0);
        var r = this.w2.count;
        this.vw.a2(this, this.v8(), runOn(this, this.vf), this.wb(b), this.wc(b));
        this.vw.r = this.ya;
        this.vw.s = this.yb;
        this.vw.k = this.ya;
        this.vw.l = this.yb;
        var s = false;
        var t = this.vw.b;
        if (t != null) {
            s = true;
        }
        var u = this.vi;
        var v = new ScalerParams(1, b.by, b.bx, u.ch);
        v.c = this.getEffectiveViewport();
        var w = 0;
        for (var x = 0; x < i.count; ++x) {
            var y = c.c4.item(x);
            var z = i._inner[x][0];
            var aa = Math.min(i._inner[x][2], h.maxLength);
            if (s) {
                this.xq(i, x, r, u, v, b.q);
            }
            var ab = this.vw.k;
            var ac = this.vw.l;
            q = (ab > 0 && ac > 0);
            var ad = null;
            if (q) {
                ad = this.yg(d, e, z - (m * 0.5), z + (m * 0.5), l, aa, n, ab, ac);
            }
            else {
                ad = this.yh(d, e, z - (m * 0.5), z + (m * 0.5), l, aa, n);
            }
            y.an = ad;
            this.vw.ad(y, false, false, false, false);
            var ae = i._inner[x][2];
            if (ae > w) {
                w = ae;
            }
        }
        c.cx = ViewportUtils.d(w, d, e);
        c.cy = { $type: Point_$type, x: ViewportUtils.c(n.x, d, e), y: ViewportUtils.f(n.y, d, e) };
        c.c4.count = i.count;
        c.c9();
    };
    RadialPieSeries.prototype.yh = function (a, b, c, d, e, f, g) {
        var h = SliceCoords.b(a, b, c, d, e, f, g);
        var i = new PathFigure();
        i._startPoint = h.d;
        i._isClosed = true;
        i._segments.add(((function () {
            var $ret = new LineSegment(1);
            $ret.c = h.f;
            return $ret;
        })()));
        i._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = h.h;
            $ret.f = h.n;
            $ret.d = 1;
            $ret.b = h.c;
            return $ret;
        })()));
        i._segments.add(((function () {
            var $ret = new LineSegment(1);
            $ret.c = h.j;
            return $ret;
        })()));
        i._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = h.d;
            $ret.f = h.m;
            $ret.d = 0;
            $ret.b = h.c;
            return $ret;
        })()));
        var j = new PathGeometry();
        j.c.add(i);
        return j;
    };
    RadialPieSeries.prototype.yg = function (a, b, c, d, e, f, g, h, i) {
        var j = SliceCoords.a(a, b, c, d, e, f, g, h, i);
        if (j == null) {
            return this.yh(a, b, c, d, e, f, g);
        }
        var k = new PathFigure();
        k._startPoint = j.d;
        k._isClosed = true;
        var l = ((c + ((d - c) * 0.5)) * 180 / Math.PI) + 90;
        var m = new Size(1, j.l.width * (e / f), j.l.height * (e / f));
        k._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = j.e;
            $ret.f = m;
            $ret.c = l;
            $ret.d = 1;
            $ret.b = false;
            return $ret;
        })()));
        k._segments.add(((function () {
            var $ret = new LineSegment(1);
            $ret.c = j.f;
            return $ret;
        })()));
        k._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = j.g;
            $ret.f = j.l;
            $ret.c = l;
            $ret.d = 1;
            $ret.b = false;
            return $ret;
        })()));
        k._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = j.h;
            $ret.f = j.n;
            $ret.d = 1;
            $ret.b = j.c;
            return $ret;
        })()));
        k._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = j.i;
            $ret.f = j.l;
            $ret.c = l;
            $ret.d = 1;
            $ret.b = false;
            return $ret;
        })()));
        k._segments.add(((function () {
            var $ret = new LineSegment(1);
            $ret.c = j.j;
            return $ret;
        })()));
        k._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = j.k;
            $ret.f = m;
            $ret.c = l;
            $ret.d = 1;
            $ret.b = false;
            return $ret;
        })()));
        k._segments.add(((function () {
            var $ret = new ArcSegment();
            $ret.e = j.d;
            $ret.f = j.m;
            $ret.d = 0;
            $ret.b = j.c;
            return $ret;
        })()));
        var n = new PathGeometry();
        n.c.add(k);
        return n;
    };
    RadialPieSeries.prototype.o8 = function (a, b, c, d) {
        _super.prototype.o8.call(this, a, b, c, d);
        switch (b) {
            case RadialPieSeries.$$p[0]:
            case RadialPieSeries.$$p[1]:
                this.o2();
                break;
        }
    };
    RadialPieSeries.$t = markType(RadialPieSeries, 'RadialPieSeries', AnchoredRadialSeries.$);
    RadialPieSeries.$$p = markDep(DependencyProperty, PropertyMetadata, RadialPieSeries, 'raisePropertyChanged', ['RadiusX:ya:ye', [1, 2], 'RadiusY:yb:yf', [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.c3 = null;
        _this.c4 = null;
        _this.c5 = null;
        _this.da = new Path();
        _this.c3 = a;
        _this.c4 = ((function () {
            var $ret = new Pool$1(Path.$);
            $ret.create = runOn(_this, _this.db);
            $ret.activate = runOn(_this, _this.c6);
            $ret.disactivate = runOn(_this, _this.c8);
            $ret.destroy = runOn(_this, _this.c7);
            return $ret;
        })());
        return _this;
    }
    RadialPieSeriesView.prototype.au = function () {
        _super.prototype.au.call(this);
        this.c5 = new List$1(Path.$, 0);
        if (!this.q) {
            this.cu.ua = Defaults.c;
            this.cu.iu = Defaults.i;
        }
    };
    RadialPieSeriesView.prototype.db = 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.c5.add(a);
        a._visibility = 1;
        return a;
    };
    RadialPieSeriesView.prototype.c6 = function (a) {
        a._visibility = 0;
    };
    RadialPieSeriesView.prototype.c8 = function (a) {
        a._visibility = 1;
    };
    RadialPieSeriesView.prototype.c7 = function (a) {
        this.c5.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.c5._inner[a];
    };
    RadialPieSeriesView.prototype.ab = function (a) {
        var b = this.c5._inner[a];
        this.da._visibility = b._visibility;
        this.da.an = b.an;
        var c = this.bs(a);
        this.da._fill = c;
        this.da._stroke = c;
        this.da.ad = this.e.hk;
        return this.da;
    };
    RadialPieSeriesView.prototype.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        if (a.d) {
            for (var c = 0; c < this.c5.count; c++) {
                var d = this.aa(c, b);
                a.t(d);
            }
        }
    };
    RadialPieSeriesView.prototype.c9 = 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.c4.a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var c = _c.value;
                this.e.a9.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 };
