/*
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.bc = function () {
        return new RadialPieSeries();
    };
    RadialPieSeries.prototype.get_e1 = function () {
        return true;
    };
    RadialPieSeries.prototype.get_ez = function () {
        return true;
    };
    RadialPieSeries.prototype.iq = function () {
        if (!isNaN_(this.ip)) {
            return _super.prototype.iq.call(this);
        }
        return Defaults.h;
    };
    RadialPieSeries.prototype.cd = function () {
        return new RadialPieSeriesView(this);
    };
    RadialPieSeries.prototype.o2 = function (a) {
        _super.prototype.o2.call(this, a);
        this.yb = a;
    };
    RadialPieSeries.prototype.preferredCategoryMode = function (a) {
        return a != null && a == this.vk ? 2 : 0;
    };
    RadialPieSeries.prototype.nk = function (a, b) {
        _super.prototype.nk.call(this, a, b);
        var c = b;
        if (a && c.c4 != null) {
            c.c4.count = 0;
        }
    };
    RadialPieSeries.prototype.h1 = function () {
        return this.vk.k4(this.cg.by, this.cg.bx, this.getEffectiveViewport1(this.cg));
    };
    RadialPieSeries.prototype.get_dv = function () {
        return true;
    };
    RadialPieSeries.prototype.wq = function (a, b) {
        _super.prototype.wq.call(this, a, b);
        var c = b;
        var d = b.by;
        var e = b.bx;
        var f = this.getEffectiveViewport1(b);
        var g = this.tq(b);
        var h = this.vm.k1(e, d, f, g);
        var i = a.f;
        var j = this.vm;
        var k = Math.max(0, 0.5 * j.nn);
        var l = k;
        l = Math.max(l, h.minLength);
        var m = this.vk.k4(d, e, f);
        var n = { $type: Point_$type, x: 0.5, y: 0.5 };
        var o = this.yc;
        var p = this.yd;
        var q = (o > 0 && p > 0);
        var r = this.w4.count;
        this.vt.a2(this, this.wa(), runOn(this, this.vh), this.wd(b), this.we(b));
        this.vt.r = this.yc;
        this.vt.s = this.yd;
        this.vt.k = this.yc;
        this.vt.l = this.yd;
        var s = false;
        var t = this.vt.b;
        if (t != null) {
            s = true;
        }
        var u = this.vk;
        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.xs(i, x, r, u, v, b.q);
            }
            var ab = this.vt.k;
            var ac = this.vt.l;
            q = (ab > 0 && ac > 0);
            var ad = null;
            if (q) {
                ad = this.yi(d, e, z - (m * 0.5), z + (m * 0.5), l, aa, n, ab, ac);
            }
            else {
                ad = this.yj(d, e, z - (m * 0.5), z + (m * 0.5), l, aa, n);
            }
            y.an = ad;
            this.vt.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.yj = 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.yi = 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.yj(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.pa = function (a, b, c, d) {
        _super.prototype.pa.call(this, a, b, c, d);
        switch (b) {
            case RadialPieSeries.$$p[0]:
            case RadialPieSeries.$$p[1]:
                this.o4();
                break;
        }
    };
    RadialPieSeries.$t = markType(RadialPieSeries, 'RadialPieSeries', AnchoredRadialSeries.$);
    RadialPieSeries.$$p = markDep(DependencyProperty, PropertyMetadata, RadialPieSeries, 'raisePropertyChanged', ['RadiusX:yc:yg', [1, 2], 'RadiusY:yd:yh', [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.uc = Defaults.c;
            this.cu.iv = 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.hl;
        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.a5.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 };
