/*
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 { CategoryAngleAxis } from "./CategoryAngleAxis";
import { ICoalescingModerator_$type } from "./ICoalescingModerator";
import { DependencyProperty } from "igniteui-react-core";
import { OthersCategoryType_$type } from "igniteui-react-core";
import { typeCast, Number_$type, enumGetBox, fromEnum, Boolean_$type, markType, markDep } from "igniteui-react-core";
import { OthersCategoryContext } from "./OthersCategoryContext";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { SeriesViewer } from "./SeriesViewer";
import { List$1 } from "igniteui-react-core";
import { CoreGeometryUtil } from "igniteui-react-core";
import { ArrayExtension } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity } from "igniteui-react-core";
/**
 * @hidden
 */
export let ProportionalCategoryAngleAxis = /*@__PURE__*/ (() => {
    class ProportionalCategoryAngleAxis extends CategoryAngleAxis {
        constructor() {
            super(...arguments);
            this.od = null;
            this.nz = null;
            this.n3 = true;
            this.n8 = NaN;
            this.n6 = new List$1(Number_$type, 0);
            this.n5 = new List$1(Number_$type, 0);
            this.n4 = new List$1(Boolean_$type, 0);
            this.n2 = false;
            this.n7 = NaN;
            this.oc = -1;
        }
        get ok() {
            return this.od;
        }
        set ok(a) {
            let b = this.ok;
            if (a != b) {
                this.od = a;
                this.h5("ValueMemberPath", b, this.ok);
            }
        }
        fz(a, b) {
            let c = this.gu(b);
            if (this.hasOthersCategory && c == "Label") {
                if (typeCast(OthersCategoryContext.$, a) !== null) {
                    return this.oi();
                }
            }
            return super.fz(a, b);
        }
        get normalizationMayContainUnknowns() {
            return this.n1 == null || this.n1.mayContainUnknowns;
        }
        get n1() {
            return this.nz;
        }
        set n1(a) {
            if (this.nz != a) {
                let b = this.nz;
                this.nz = a;
                this.h5("ValueColumn", b, this.nz);
            }
        }
        n0(a) {
            if (a == null) {
                return this.kv.registerColumn(null, null, false);
            }
            let b = null;
            let c = SeriesViewer.cu(a, this.coercionMethods);
            b = c.a;
            return this.kv.registerColumn(a, b, this.expectFunctions);
        }
        hz(a, b, c, d) {
            super.hz(a, b, c, d);
            switch (b) {
                case "ValueMemberPath":
                    if (this.kv != null) {
                        this.kv.deregisterColumn(this.n1);
                        this.n1 = this.n0(this.ok);
                    }
                    break;
                case "ValueColumn":
                    this.n3 = true;
                    this.n2 = false;
                    this.ia();
                    break;
                case ProportionalCategoryAngleAxis.$$p[0]:
                case ProportionalCategoryAngleAxis.$$p[1]:
                case ProportionalCategoryAngleAxis.$$p[2]:
                    this.n3 = true;
                    this.n2 = false;
                    this.ia();
                    for (let e of fromEnum(this.db())) {
                        e.rp(true);
                    }
                    break;
                case "FastItemsSource":
                    this.n3 = true;
                    this.n2 = false;
                    let f = typeCast(IFastItemsSource_$type, c);
                    if (f != null) {
                        f.deregisterColumn(this.n1);
                        this.n1 = null;
                    }
                    let g = typeCast(IFastItemsSource_$type, d);
                    if (g != null) {
                        this.n1 = this.n0(this.ok);
                    }
                    this.ia();
                    break;
            }
        }
        l7(a) {
            super.l7(a);
            this.n3 = true;
            this.n2 = false;
        }
        getScaledAngle(a) {
            this.om();
            if (isNaN_(a) || isInfinity(a)) {
                return NaN;
            }
            let b = this.lj;
            let c = a % b;
            if (c < 0) {
                c = b + c;
            }
            let d = truncate(Math.floor(c));
            let e = this.n5._inner[d];
            let f = c - d;
            let g = 0;
            if (isNaN_(this.n6._inner[d])) {
                g = 0 * f;
            }
            else {
                g = this.n6._inner[d] * f;
            }
            let h = e + g;
            if (this.ci) {
                h = 1 - h;
            }
            let i = (h * 2 * Math.PI);
            if (a >= b) {
                i += (2 * Math.PI) * Math.floor(a / b);
            }
            if (a < 0) {
                i -= (2 * Math.PI) * Math.abs(Math.floor(a / b));
            }
            return i + this.m2;
        }
        get_cl() {
            return true;
        }
        m6(a, b, c, d, e) {
            let f = 0.5;
            if (this.ll > 1) {
                let g = this.lf(c, d, e);
                let h = 0;
                if (!isNaN_(this.le)) {
                    h = Math.min(this.le, 1);
                }
                let i = 1 - 0.5 * g;
                let j = i / (this.ll - (this.ll - 1) * h);
                let k = (i - j) / (this.ll - 1);
                f = 0.25 * g + 0.5 * j + a * k;
            }
            return this.n9(a, c, d, e) * f;
        }
        n9(a, b, c, d) {
            if (a < 0 || a > this.lk - 1) {
                return this.getCategorySize(b, c, d);
            }
            this.om();
            let e = this.n6._inner[a];
            if (isNaN_(e)) {
                return NaN;
            }
            let f = Math.PI * 2 * this.n6._inner[a];
            return f;
        }
        m7(a, b, c, d) {
            this.om();
            let e = this.lf(b, c, d);
            let f = 0;
            if (!isNaN_(this.le)) {
                f = Math.min(this.le, 1);
            }
            let g = 1 - 0.5 * e;
            if (a < 0 || a > this.lk - 1) {
                return this.k8(b, c, d);
            }
            let h = this.n6._inner[a];
            if (isNaN_(h)) {
                return NaN;
            }
            let i = Math.PI * 2 * h;
            return i * g / (this.ll - (this.ll - 1) * f);
        }
        lm() {
            if (this.kv == null) {
                return 0;
            }
            this.om();
            if (this.n2) {
                return super.lm() + 1;
            }
            return super.lm();
        }
        mx(a) {
            return this.hasOthersCategory && a == this.lk - 1;
        }
        nk() {
            return this.oi();
        }
        my(a) {
            if (a >= 0 && a < this.lk) {
                if (isNaN_(this.n6._inner[a])) {
                    return true;
                }
            }
            return super.my(a);
        }
        ic(a) {
            this.om();
            super.ic(a);
        }
        ensureSum() {
            this.om();
        }
        om() {
            if (this.n3) {
                this.n3 = false;
                this.n2 = false;
                this.lk = this.lm();
                this.n7 = NaN;
                this.oc = -1;
                if (this.n1 != null && this.n1.count > 0) {
                    this.n8 = NaN;
                    let a = true;
                    for (let b = 0; b < this.n1.count; b++) {
                        let c = this.n1.item(b);
                        if (isNaN_(c) || isInfinity(c) || c < 0) {
                            continue;
                        }
                        if (a) {
                            a = false;
                            this.n8 = 0;
                        }
                        this.n8 += c;
                    }
                    let d = 0;
                    this.n6.clear();
                    this.n5.clear();
                    this.n4.clear();
                    let e = 0;
                    for (let f = 0; f < this.n1.count; f++) {
                        let g = 0;
                        if (isNaN_(this.n8)) {
                            g = 1 / this.lk;
                        }
                        else {
                            let h = this.n1.item(f);
                            if (isNaN_(h) || isInfinity(h) || h < 0) {
                                g = 0;
                            }
                            else {
                                g = h;
                            }
                        }
                        let i = false;
                        if (this.ny == 0) {
                            if (g < this.ob) {
                                i = true;
                            }
                        }
                        else {
                            if ((g / this.n8) * 100 < this.ob) {
                                i = true;
                            }
                        }
                        if (i) {
                            this.n5.add(d);
                            this.n6.add(NaN);
                            this.n4.add(true);
                            e += g;
                        }
                        else {
                            this.n5.add(d);
                            this.n6.add(g / this.n8);
                            this.n4.add(false);
                            d += (g / this.n8);
                        }
                    }
                    if (e > 0) {
                        this.n2 = true;
                        this.n5.add(d);
                        this.n6.add(e / this.n8);
                        this.n4.add(false);
                        this.n7 = e;
                        this.oc = this.n5.count - 1;
                    }
                }
                else {
                    if (this.lk > 0) {
                        this.n6.clear();
                        this.n5.clear();
                        let j = 0;
                        for (let k = 0; k < this.lk; k++) {
                            this.n5.add(j);
                            this.n6.add(1 / this.lk);
                            j += (1 / this.lk);
                        }
                    }
                }
                this.lk = this.lm();
            }
        }
        get othersValue() {
            return this.n7;
        }
        get othersIndex() {
            return this.oc;
        }
        get hasOthersCategory() {
            return this.n2;
        }
        hq(a, b, c, d) {
            for (let e = b; e < c; e++) {
                a.item(e, this.el(a.item(e), d));
            }
        }
        getUnscaledAngle(a) {
            this.om();
            if (isNaN_(a) || isInfinity(a)) {
                return NaN;
            }
            a = CoreGeometryUtil.b(a);
            while (a < this.m2) {
                a += 2 * Math.PI;
            }
            while (a > (this.m2 + (2 * Math.PI))) {
                a -= 2 * Math.PI;
            }
            let b = (a - this.m2) / (2 * Math.PI);
            if (this.ch) {
                b = 1 - b;
            }
            let c = -1;
            c = ArrayExtension.binarySearch$11(Number_$type, this.n5, (d) => b < d ? -1 : (b > d ? 1 : 0));
            if (c < 0) {
                c = ~c;
                c--;
            }
            if (c < 0) {
                c = 0;
            }
            if (c > this.n5.count - 1) {
                c = this.n5.count - 1;
            }
            let d = this.n5._inner[c];
            let e = this.n6._inner[c];
            if (isNaN_(e)) {
                b = c;
            }
            else {
                b = c + (b - d) / e;
            }
            return b;
        }
        isOthersValue(a) {
            if (a < 0 || a > this.n4.count - 1) {
                return false;
            }
            return this.n4._inner[a];
        }
        gf(a) {
            let b = a;
            if (this.categoryMode == 0) {
                b = truncate(Math.round(a));
            }
            else {
                b = truncate(Math.floor(a));
            }
            if (this.hasOthersCategory && b >= this.lk - 1) {
                b = this.lk - 1;
                return this.oi();
            }
            return super.gf(a);
        }
        oi() {
            if (this.oe != null) {
                return this.oe;
            }
            return "Others";
        }
        getNormalizingValueAtIndex(a, b) {
            if (a < 0 || this.n1 == null || a > this.n1.count - 1) {
                return b;
            }
            return this.n1.item(a);
        }
        oa(a) {
            this.om();
            let b = this.n6._inner[a] * 100;
            return b;
        }
        get isVertical() {
            return this.cp;
        }
        j$d(a, b) {
            return this.eo.apply(this, arguments);
        }
        j$c(a, b) {
            return this.el.apply(this, arguments);
        }
        j$e(a, b, c, d, e) {
            this.hp.apply(this, arguments);
        }
        j$f(a, b, c, d) {
            this.hq.apply(this, arguments);
        }
        j$g(a, b, c, d) {
            this.hr.apply(this, arguments);
        }
        get j$b() {
            return this.ch;
        }
        j$a() {
            return this.ag.apply(this, arguments);
        }
        get itemsCount() {
            return this.lk;
        }
    }
    ProportionalCategoryAngleAxis.$t = /*@__PURE__*/ markType(ProportionalCategoryAngleAxis, 'ProportionalCategoryAngleAxis', CategoryAngleAxis.$, [ICoalescingModerator_$type]);
    ProportionalCategoryAngleAxis.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, ProportionalCategoryAngleAxis, 'h5', ['OthersCategoryText:oe:on', [2, null], 'OthersCategoryThreshold:ob:oo', [1, 3], 'OthersCategoryType:ny:op', [OthersCategoryType_$type, /*@__PURE__*/ enumGetBox(OthersCategoryType_$type, 1)]]);
    return ProportionalCategoryAngleAxis;
})();
