/*
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, 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.n9 = null;
            this.nv = null;
            this.nz = true;
            this.n4 = NaN;
            this.n2 = new List$1(Number_$type, 0);
            this.n1 = new List$1(Number_$type, 0);
            this.n0 = new List$1(Boolean_$type, 0);
            this.ny = false;
            this.n3 = NaN;
            this.n8 = -1;
        }
        get og() {
            return this.n9;
        }
        set og(a) {
            let b = this.og;
            if (a != b) {
                this.n9 = a;
                this.h3("ValueMemberPath", b, this.og);
            }
        }
        fy(a, b) {
            let c = this.gt(b);
            if (this.hasOthersCategory && c == "Label") {
                if (typeCast(OthersCategoryContext.$, a) !== null) {
                    return this.oe();
                }
            }
            return super.fy(a, b);
        }
        get normalizationMayContainUnknowns() {
            return this.nx == null || this.nx.mayContainUnknowns;
        }
        get nx() {
            return this.nv;
        }
        set nx(a) {
            if (this.nv != a) {
                let b = this.nv;
                this.nv = a;
                this.h3("ValueColumn", b, this.nv);
            }
        }
        nw(a) {
            if (a == null) {
                return this.ks.registerColumn(null, null, false);
            }
            let b = null;
            let c = SeriesViewer.cu(a, this.coercionMethods);
            b = c.a;
            return this.ks.registerColumn(a, b, this.expectFunctions);
        }
        hx(a, b, c, d) {
            super.hx(a, b, c, d);
            switch (b) {
                case "ValueMemberPath":
                    if (this.ks != null) {
                        this.ks.deregisterColumn(this.nx);
                        this.nx = this.nw(this.og);
                    }
                    break;
                case "ValueColumn":
                    this.nz = true;
                    this.ny = false;
                    this.h8();
                    break;
                case ProportionalCategoryAngleAxis.$$p[0]:
                case ProportionalCategoryAngleAxis.$$p[1]:
                case ProportionalCategoryAngleAxis.$$p[2]:
                    this.nz = true;
                    this.ny = false;
                    this.h8();
                    break;
                case "FastItemsSource":
                    this.nz = true;
                    this.ny = false;
                    let e = typeCast(IFastItemsSource_$type, c);
                    if (e != null) {
                        e.deregisterColumn(this.nx);
                        this.nx = null;
                    }
                    let f = typeCast(IFastItemsSource_$type, d);
                    if (f != null) {
                        this.nx = this.nw(this.og);
                    }
                    this.h8();
                    break;
            }
        }
        l4(a) {
            super.l4(a);
            this.nz = true;
            this.ny = false;
        }
        getScaledAngle(a) {
            this.oi();
            if (isNaN_(a) || isInfinity(a)) {
                return NaN;
            }
            let b = this.lg;
            let c = a % b;
            if (c < 0) {
                c = b + c;
            }
            let d = truncate(Math.floor(c));
            let e = this.n1._inner[d];
            let f = c - d;
            let g = 0;
            if (isNaN_(this.n2._inner[d])) {
                g = 0 * f;
            }
            else {
                g = this.n2._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.mz;
        }
        get_cl() {
            return true;
        }
        m3(a, b, c, d, e) {
            let f = 0.5;
            if (this.li > 1) {
                let g = this.lc(c, d, e);
                let h = 0;
                if (!isNaN_(this.lb)) {
                    h = Math.min(this.lb, 1);
                }
                let i = 1 - 0.5 * g;
                let j = i / (this.li - (this.li - 1) * h);
                let k = (i - j) / (this.li - 1);
                f = 0.25 * g + 0.5 * j + a * k;
            }
            return this.n5(a, c, d, e) * f;
        }
        n5(a, b, c, d) {
            if (a < 0 || a > this.lh - 1) {
                return this.getCategorySize(b, c, d);
            }
            this.oi();
            let e = this.n2._inner[a];
            if (isNaN_(e)) {
                return NaN;
            }
            let f = Math.PI * 2 * this.n2._inner[a];
            return f;
        }
        m4(a, b, c, d) {
            this.oi();
            let e = this.lc(b, c, d);
            let f = 0;
            if (!isNaN_(this.lb)) {
                f = Math.min(this.lb, 1);
            }
            let g = 1 - 0.5 * e;
            if (a < 0 || a > this.lh - 1) {
                return this.k5(b, c, d);
            }
            let h = this.n2._inner[a];
            if (isNaN_(h)) {
                return NaN;
            }
            let i = Math.PI * 2 * h;
            return i * g / (this.li - (this.li - 1) * f);
        }
        lj() {
            if (this.ks == null) {
                return 0;
            }
            this.oi();
            if (this.ny) {
                return super.lj() + 1;
            }
            return super.lj();
        }
        mu(a) {
            return this.hasOthersCategory && a == this.lh - 1;
        }
        ng() {
            return this.oe();
        }
        mv(a) {
            if (a >= 0 && a < this.lh) {
                if (isNaN_(this.n2._inner[a])) {
                    return true;
                }
            }
            return super.mv(a);
        }
        ia(a) {
            this.oi();
            super.ia(a);
        }
        ensureSum() {
            this.oi();
        }
        oi() {
            if (this.nz) {
                this.nz = false;
                this.ny = false;
                this.lh = this.lj();
                this.n3 = NaN;
                this.n8 = -1;
                if (this.nx != null && this.nx.count > 0) {
                    this.n4 = NaN;
                    let a = true;
                    for (let b = 0; b < this.nx.count; b++) {
                        let c = this.nx.item(b);
                        if (isNaN_(c) || isInfinity(c) || c < 0) {
                            continue;
                        }
                        if (a) {
                            a = false;
                            this.n4 = 0;
                        }
                        this.n4 += c;
                    }
                    let d = 0;
                    this.n2.clear();
                    this.n1.clear();
                    this.n0.clear();
                    let e = 0;
                    for (let f = 0; f < this.nx.count; f++) {
                        let g = 0;
                        if (isNaN_(this.n4)) {
                            g = 1 / this.lh;
                        }
                        else {
                            let h = this.nx.item(f);
                            if (isNaN_(h) || isInfinity(h) || h < 0) {
                                g = 0;
                            }
                            else {
                                g = h;
                            }
                        }
                        let i = false;
                        if (this.nu == 0) {
                            if (g < this.n7) {
                                i = true;
                            }
                        }
                        else {
                            if ((g / this.n4) * 100 < this.n7) {
                                i = true;
                            }
                        }
                        if (i) {
                            this.n1.add(d);
                            this.n2.add(NaN);
                            this.n0.add(true);
                            e += g;
                        }
                        else {
                            this.n1.add(d);
                            this.n2.add(g / this.n4);
                            this.n0.add(false);
                            d += (g / this.n4);
                        }
                    }
                    if (e > 0) {
                        this.ny = true;
                        this.n1.add(d);
                        this.n2.add(e / this.n4);
                        this.n0.add(false);
                        this.n3 = e;
                        this.n8 = this.n1.count - 1;
                    }
                }
                else {
                    if (this.lh > 0) {
                        this.n2.clear();
                        this.n1.clear();
                        let j = 0;
                        for (let k = 0; k < this.lh; k++) {
                            this.n1.add(j);
                            this.n2.add(1 / this.lh);
                            j += (1 / this.lh);
                        }
                    }
                }
                this.lh = this.lj();
            }
        }
        get othersValue() {
            return this.n3;
        }
        get othersIndex() {
            return this.n8;
        }
        get hasOthersCategory() {
            return this.ny;
        }
        ho(a, b, c, d) {
            for (let e = b; e < c; e++) {
                a.item(e, this.ek(a.item(e), d));
            }
        }
        getUnscaledAngle(a) {
            this.oi();
            if (isNaN_(a) || isInfinity(a)) {
                return NaN;
            }
            a = CoreGeometryUtil.b(a);
            while (a < this.mz) {
                a += 2 * Math.PI;
            }
            while (a > (this.mz + (2 * Math.PI))) {
                a -= 2 * Math.PI;
            }
            let b = (a - this.mz) / (2 * Math.PI);
            if (this.ch) {
                b = 1 - b;
            }
            let c = -1;
            c = ArrayExtension.binarySearch$11(Number_$type, this.n1, (d) => b < d ? -1 : (b > d ? 1 : 0));
            if (c < 0) {
                c = ~c;
                c--;
            }
            if (c < 0) {
                c = 0;
            }
            if (c > this.n1.count - 1) {
                c = this.n1.count - 1;
            }
            let d = this.n1._inner[c];
            let e = this.n2._inner[c];
            if (isNaN_(e)) {
                b = c;
            }
            else {
                b = c + (b - d) / e;
            }
            return b;
        }
        isOthersValue(a) {
            if (a < 0 || a > this.n0.count - 1) {
                return false;
            }
            return this.n0._inner[a];
        }
        ge(a) {
            let b = a;
            if (this.categoryMode == 0) {
                b = truncate(Math.round(a));
            }
            else {
                b = truncate(Math.floor(a));
            }
            if (this.hasOthersCategory && b >= this.lh - 1) {
                b = this.lh - 1;
                return this.oe();
            }
            return super.ge(a);
        }
        oe() {
            if (this.oa != null) {
                return this.oa;
            }
            return "Others";
        }
        getNormalizingValueAtIndex(a, b) {
            if (a < 0 || this.nx == null || a > this.nx.count - 1) {
                return b;
            }
            return this.nx.item(a);
        }
        n6(a) {
            this.oi();
            let b = this.n2._inner[a] * 100;
            return b;
        }
        get isVertical() {
            return this.cp;
        }
        j$d(a, b) {
            return this.en.apply(this, arguments);
        }
        j$c(a, b) {
            return this.ek.apply(this, arguments);
        }
        j$e(a, b, c, d, e) {
            this.hn.apply(this, arguments);
        }
        j$f(a, b, c, d) {
            this.ho.apply(this, arguments);
        }
        j$g(a, b, c, d) {
            this.hp.apply(this, arguments);
        }
        get j$b() {
            return this.ch;
        }
        j$a() {
            return this.ag.apply(this, arguments);
        }
        get itemsCount() {
            return this.lh;
        }
    }
    ProportionalCategoryAngleAxis.$t = /*@__PURE__*/ markType(ProportionalCategoryAngleAxis, 'ProportionalCategoryAngleAxis', CategoryAngleAxis.$, [ICoalescingModerator_$type]);
    ProportionalCategoryAngleAxis.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, ProportionalCategoryAngleAxis, 'h3', ['OthersCategoryText:oa:oj', [2, null], 'OthersCategoryThreshold:n7:ok', [1, 3], 'OthersCategoryType:nu:ol', [OthersCategoryType_$type, /*@__PURE__*/ enumGetBox(OthersCategoryType_$type, 1)]]);
    return ProportionalCategoryAngleAxis;
})();
