/*
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 { AnchoredRadialSeries } from "./AnchoredRadialSeries";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { Type, Point_$type, markType, runOn, fromEnum } from "igniteui-react-core/ES5/type";
import { Pool$1 } from "igniteui-react-core/ES5/Pool$1";
import { Path } from "igniteui-react-core/ES5/Path";
import { List$1 } from "igniteui-react-core/ES5/List$1";
import { PathGeometry } from "igniteui-react-core/ES5/PathGeometry";
import { ViewportUtils } from "./ViewportUtils";
import { SliceCoords } from "./SliceCoords";
import { PathFigure } from "igniteui-react-core/ES5/PathFigure";
import { LineSegment } from "igniteui-react-core/ES5/LineSegment";
import { ArcSegment } from "igniteui-react-core/ES5/ArcSegment";
import { Size } from "igniteui-react-core/ES5/Size";
import { PropertyMetadata } from "igniteui-react-core/ES5/PropertyMetadata";
import { AnchoredRadialSeriesView } from "./AnchoredRadialSeriesView";
import { DataContext } from "igniteui-react-core/ES5/DataContext";
/**
 * @hidden
 */
var RadialPieSeries = /** @class */ (function (_super) {
    tslib_1.__extends(RadialPieSeries, _super);
    function RadialPieSeries() {
        var _this = _super.call(this) || this;
        _this.ab = RadialPieSeries.$;
        return _this;
    }
    RadialPieSeries.prototype.bf = function () {
        return new RadialPieSeriesView(this);
    };
    RadialPieSeries.prototype.im = function (a) {
        _super.prototype.im.call(this, a);
        this.oj = a;
    };
    RadialPieSeries.prototype.preferredCategoryMode = function (a) {
        return a != null && a == this.mt ? 2 : 0;
    };
    RadialPieSeries.prototype.hp = function (a, b) {
        _super.prototype.hp.call(this, a, b);
        var c = b;
        if (a && c.cx != null) {
            c.cx.count = 0;
        }
    };
    RadialPieSeries.prototype.ed = function () {
        return this.mt.jk(this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
    };
    RadialPieSeries.prototype.ne = function (a, b) {
        _super.prototype.ne.call(this, a, b);
        var c = b;
        var d = b.bs;
        var e = b.br;
        var f = this.getEffectiveViewport1(b);
        var g = this.lj(b);
        var h = this.mv.i9(e, d, f, g);
        var i = a.f;
        var j = this.mv;
        var k = Math.max(0, 0.5 * j.lb);
        var l = k;
        l = Math.max(l, h.minLength);
        var m = this.mt.jk(d, e, f);
        var n = { $type: Point_$type, x: 0.5, y: 0.5 };
        var o = this.ok;
        var p = this.ol;
        var q = (o > 0 && p > 0);
        var r = 0;
        for (var s = 0; s < i.count; ++s) {
            var t = c.cx.item(s);
            var u = i._inner[s][0];
            var v = Math.min(i._inner[s][2], h.maxLength);
            var w = null;
            if (q) {
                w = this.oq(d, e, u - (m * 0.5), u + (m * 0.5), l, v, n, o, p);
            }
            else {
                w = this.or(d, e, u - (m * 0.5), u + (m * 0.5), l, v, n);
            }
            t.aj = w;
            var x = i._inner[s][2];
            if (x > r) {
                r = x;
            }
        }
        c.cq = ViewportUtils.d(r, d, e);
        c.cr = { $type: Point_$type, x: ViewportUtils.c(n.x, d, e), y: ViewportUtils.f(n.y, d, e) };
        c.cx.count = i.count;
        c.c2();
    };
    RadialPieSeries.prototype.or = 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.b.add(i);
        return j;
    };
    RadialPieSeries.prototype.oq = 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.or(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.b.add(k);
        return n;
    };
    RadialPieSeries.prototype.is = function (a, b, c, d) {
        _super.prototype.is.call(this, a, b, c, d);
        switch (b) {
            case RadialPieSeries.$$p[0]:
            case RadialPieSeries.$$p[1]:
                this.i6(false);
                break;
        }
    };
    RadialPieSeries.$t = markType(RadialPieSeries, 'RadialPieSeries', AnchoredRadialSeries.$);
    return RadialPieSeries;
}(AnchoredRadialSeries));
export { RadialPieSeries };
Type.dep(DependencyProperty, PropertyMetadata, RadialPieSeries, 'raisePropertyChanged', ['RadiusX:ok:oo', [1, 2], 'RadiusY:ol:op', [1, 2]]);
/**
 * @hidden
 */
var RadialPieSeriesView = /** @class */ (function (_super) {
    tslib_1.__extends(RadialPieSeriesView, _super);
    function RadialPieSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.cw = null;
        _this.cx = null;
        _this.cy = null;
        _this.cw = a;
        _this.cx = ((function () {
            var $ret = new Pool$1(Path.$);
            $ret.create = runOn(_this, _this.c3);
            $ret.activate = runOn(_this, _this.cz);
            $ret.disactivate = runOn(_this, _this.c1);
            $ret.destroy = runOn(_this, _this.c0);
            return $ret;
        })());
        return _this;
    }
    RadialPieSeriesView.prototype.ap = function () {
        _super.prototype.ap.call(this);
        this.cy = new List$1(Path.$, 0);
        if (!this.n) {
            this.e.er = 4;
            this.e.bj = 1;
        }
    };
    RadialPieSeriesView.prototype.c3 = 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.cy.add(a);
        a._visibility = 1;
        return a;
    };
    RadialPieSeriesView.prototype.cz = function (a) {
        a._visibility = 0;
    };
    RadialPieSeriesView.prototype.c1 = function (a) {
        a._visibility = 1;
    };
    RadialPieSeriesView.prototype.c0 = function (a) {
        this.cy.remove(a);
    };
    RadialPieSeriesView.prototype.bb = function (a, b) {
        _super.prototype.bb.call(this, a, b);
        var c = a;
        c._stroke = this.e.kx;
        c.ac = this.e.ev;
        c._fill = this.e.kw;
        c.ai = this.e.k4;
        c.ad = this.e.k5;
    };
    RadialPieSeriesView.prototype.bc = function (a, b) {
        _super.prototype.bc.call(this, a, b);
        var c = a;
        var d = this.bm(b);
        c._stroke = d;
        c.ac = this.e.ev;
        c._fill = d;
    };
    RadialPieSeriesView.prototype.a3 = function (a, b) {
        _super.prototype.a3.call(this, a, b);
        if (a.d) {
            for (var c = 0; c < this.cy.count; c++) {
                var d = this.cy._inner[c];
                this.ba(d, c, b);
                a.s(d);
            }
        }
    };
    RadialPieSeriesView.prototype.c2 = function () {
        this.an();
    };
    RadialPieSeriesView.prototype.ai = function (a) {
        var e_1, _a;
        _super.prototype.ai.call(this, a);
        var b = 0;
        try {
            for (var _b = tslib_1.__values(fromEnum(this.cx.a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var c = _c.value;
                this.e.a2.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 };
