/*
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 { AnchoredRadialSeries } from "./AnchoredRadialSeries";
import { DependencyProperty } from "igniteui-react-core/ES2015/DependencyProperty";
import { Type, Point_$type, markType, runOn, fromEnum } from "igniteui-react-core/ES2015/type";
import { Pool$1 } from "igniteui-react-core/ES2015/Pool$1";
import { Path } from "igniteui-react-core/ES2015/Path";
import { List$1 } from "igniteui-react-core/ES2015/List$1";
import { PathGeometry } from "igniteui-react-core/ES2015/PathGeometry";
import { ViewportUtils } from "./ViewportUtils";
import { SliceCoords } from "./SliceCoords";
import { PathFigure } from "igniteui-react-core/ES2015/PathFigure";
import { LineSegment } from "igniteui-react-core/ES2015/LineSegment";
import { ArcSegment } from "igniteui-react-core/ES2015/ArcSegment";
import { Size } from "igniteui-react-core/ES2015/Size";
import { PropertyMetadata } from "igniteui-react-core/ES2015/PropertyMetadata";
import { AnchoredRadialSeriesView } from "./AnchoredRadialSeriesView";
import { DataContext } from "igniteui-react-core/ES2015/DataContext";
/**
 * @hidden
 */
export class RadialPieSeries extends AnchoredRadialSeries {
    constructor() {
        super();
        this.ab = RadialPieSeries.$;
    }
    bf() {
        return new RadialPieSeriesView(this);
    }
    im(a) {
        super.im(a);
        this.oj = a;
    }
    preferredCategoryMode(a) {
        return a != null && a == this.mt ? 2 : 0;
    }
    hp(a, b) {
        super.hp(a, b);
        let c = b;
        if (a && c.cx != null) {
            c.cx.count = 0;
        }
    }
    ed() {
        return this.mt.jk(this.bi.bs, this.bi.br, this.getEffectiveViewport1(this.bi));
    }
    ne(a, b) {
        super.ne(a, b);
        let c = b;
        let d = b.bs;
        let e = b.br;
        let f = this.getEffectiveViewport1(b);
        let g = this.lj(b);
        let h = this.mv.i9(e, d, f, g);
        let i = a.f;
        let j = this.mv;
        let k = Math.max(0, 0.5 * j.lb);
        let l = k;
        l = Math.max(l, h.minLength);
        let m = this.mt.jk(d, e, f);
        let n = { $type: Point_$type, x: 0.5, y: 0.5 };
        let o = this.ok;
        let p = this.ol;
        let q = (o > 0 && p > 0);
        let r = 0;
        for (let s = 0; s < i.count; ++s) {
            let t = c.cx.item(s);
            let u = i._inner[s][0];
            let v = Math.min(i._inner[s][2], h.maxLength);
            let 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;
            let 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();
    }
    or(a, b, c, d, e, f, g) {
        let h = SliceCoords.b(a, b, c, d, e, f, g);
        let i = new PathFigure();
        i._startPoint = h.d;
        i._isClosed = true;
        i._segments.add(((() => {
            let $ret = new LineSegment(1);
            $ret.c = h.f;
            return $ret;
        })()));
        i._segments.add(((() => {
            let $ret = new ArcSegment();
            $ret.e = h.h;
            $ret.f = h.n;
            $ret.d = 1;
            $ret.b = h.c;
            return $ret;
        })()));
        i._segments.add(((() => {
            let $ret = new LineSegment(1);
            $ret.c = h.j;
            return $ret;
        })()));
        i._segments.add(((() => {
            let $ret = new ArcSegment();
            $ret.e = h.d;
            $ret.f = h.m;
            $ret.d = 0;
            $ret.b = h.c;
            return $ret;
        })()));
        let j = new PathGeometry();
        j.b.add(i);
        return j;
    }
    oq(a, b, c, d, e, f, g, h, i) {
        let 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);
        }
        let k = new PathFigure();
        k._startPoint = j.d;
        k._isClosed = true;
        let l = ((c + ((d - c) * 0.5)) * 180 / Math.PI) + 90;
        let m = new Size(1, j.l.width * (e / f), j.l.height * (e / f));
        k._segments.add(((() => {
            let $ret = new ArcSegment();
            $ret.e = j.e;
            $ret.f = m;
            $ret.c = l;
            $ret.d = 1;
            $ret.b = false;
            return $ret;
        })()));
        k._segments.add(((() => {
            let $ret = new LineSegment(1);
            $ret.c = j.f;
            return $ret;
        })()));
        k._segments.add(((() => {
            let $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(((() => {
            let $ret = new ArcSegment();
            $ret.e = j.h;
            $ret.f = j.n;
            $ret.d = 1;
            $ret.b = j.c;
            return $ret;
        })()));
        k._segments.add(((() => {
            let $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(((() => {
            let $ret = new LineSegment(1);
            $ret.c = j.j;
            return $ret;
        })()));
        k._segments.add(((() => {
            let $ret = new ArcSegment();
            $ret.e = j.k;
            $ret.f = m;
            $ret.c = l;
            $ret.d = 1;
            $ret.b = false;
            return $ret;
        })()));
        k._segments.add(((() => {
            let $ret = new ArcSegment();
            $ret.e = j.d;
            $ret.f = j.m;
            $ret.d = 0;
            $ret.b = j.c;
            return $ret;
        })()));
        let n = new PathGeometry();
        n.b.add(k);
        return n;
    }
    is(a, b, c, d) {
        super.is(a, b, c, d);
        switch (b) {
            case RadialPieSeries.$$p[0]:
            case RadialPieSeries.$$p[1]:
                this.i6(false);
                break;
        }
    }
}
RadialPieSeries.$t = markType(RadialPieSeries, 'RadialPieSeries', AnchoredRadialSeries.$);
Type.dep(DependencyProperty, PropertyMetadata, RadialPieSeries, 'raisePropertyChanged', ['RadiusX:ok:oo', [1, 2], 'RadiusY:ol:op', [1, 2]]);
/**
 * @hidden
 */
export class RadialPieSeriesView extends AnchoredRadialSeriesView {
    constructor(a) {
        super(a);
        this.cw = null;
        this.cx = null;
        this.cy = null;
        this.cw = a;
        this.cx = ((() => {
            let $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;
        })());
    }
    ap() {
        super.ap();
        this.cy = new List$1(Path.$, 0);
        if (!this.n) {
            this.e.er = 4;
            this.e.bj = 1;
        }
    }
    c3() {
        let a = ((() => {
            let $ret = new Path();
            $ret.dataContext = ((() => {
                let $ret = new DataContext();
                $ret.series = this.e;
                return $ret;
            })());
            return $ret;
        })());
        this.cy.add(a);
        a._visibility = 1;
        return a;
    }
    cz(a) {
        a._visibility = 0;
    }
    c1(a) {
        a._visibility = 1;
    }
    c0(a) {
        this.cy.remove(a);
    }
    bb(a, b) {
        super.bb(a, b);
        let 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;
    }
    bc(a, b) {
        super.bc(a, b);
        let c = a;
        let d = this.bm(b);
        c._stroke = d;
        c.ac = this.e.ev;
        c._fill = d;
    }
    a3(a, b) {
        super.a3(a, b);
        if (a.d) {
            for (let c = 0; c < this.cy.count; c++) {
                let d = this.cy._inner[c];
                this.ba(d, c, b);
                a.s(d);
            }
        }
    }
    c2() {
        this.an();
    }
    ai(a) {
        super.ai(a);
        let b = 0;
        for (let c of fromEnum(this.cx.a)) {
            this.e.a2.exportPathData(a, c, "slice" + b, ["Main", "Fill"]);
            b++;
        }
    }
}
RadialPieSeriesView.$t = markType(RadialPieSeriesView, 'RadialPieSeriesView', AnchoredRadialSeriesView.$);
