/*
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 { Base, EnumUtil, String_$type, fromEnum, markType } from "./type";
import { IDataSeriesAdapterRule_$type } from "./IDataSeriesAdapterRule";
import { HashSet$1 } from "./HashSet$1";
import { DataSeriesIntent_$type } from "./DataSeriesIntent";
import { DataSeries } from "./DataSeries";
import { DataSeriesMemberPathHint } from "./DataSeriesMemberPathHint";
import { truncate } from "./number";
/**
 * @hidden
 */
export let SimplePieSeriesRule = /*@__PURE__*/ (() => {
    class SimplePieSeriesRule extends Base {
        constructor() {
            super();
            this._priority = 0;
            this._useColumnThreshold = 0;
            this._distinctCheckThreshold = 0;
            this.b = 1;
            this.priority = 10;
            this.distinctCheckThreshold = 50000;
            this.useColumnThreshold = 30;
        }
        get priority() {
            return this._priority;
        }
        set priority(a) {
            this._priority = a;
        }
        get useColumnThreshold() {
            return this._useColumnThreshold;
        }
        set useColumnThreshold(a) {
            this._useColumnThreshold = a;
        }
        get distinctCheckThreshold() {
            return this._distinctCheckThreshold;
        }
        set distinctCheckThreshold(a) {
            this._distinctCheckThreshold = a;
        }
        getPrimaryAxisLabelsString(a) {
            let b = 1;
            let c = ((() => { let d = SimplePieSeriesRule.f(a.analyzer, this.distinctCheckThreshold, b); b = d.p2; return d.ret; })());
            this.b = b;
            return c;
        }
        getAdditionalValuePropertyStrings(a) {
            return null;
        }
        getPrimaryAxisLabelsStrings(a) {
            let b = a.analyzer;
            let c = b.getAllPropertiesWithIntent(EnumUtil.getName(DataSeriesIntent_$type, (16)));
            if (c.length > 0) {
                for (let d = 0; d < c.length; d++) {
                    a.am(a.getCurrentPath(), c[d], 0);
                }
                return c;
            }
            let e = b.getAllStringProperties();
            let f = b.getAllDateTimeProperties();
            let g = b.getAllDistinctMonotonicNumericProperties(this.distinctCheckThreshold);
            let h = new HashSet$1(String_$type, 0);
            for (let i = 0; i < e.length; i++) {
                let j = e[i];
                h.add_1(j);
                a.am(a.getCurrentPath(), j, 0);
            }
            for (let k = 0; k < f.length; k++) {
                let l = f[k];
                h.add_1(l);
                a.am(a.getCurrentPath(), l, 1);
            }
            for (let m = 0; m < g.length; m++) {
                let n = g[m];
                h.add_1(n);
                a.am(a.getCurrentPath(), n, 2);
            }
            e = b.getAllExcludedStringProperties();
            f = b.getAllExcludedDateTimeProperties();
            g = b.getAllExcludedDistinctMonotonicNumericProperties(this.distinctCheckThreshold);
            for (let o = 0; o < e.length; o++) {
                let p = e[o];
                h.add_1(p);
                a.am(a.getCurrentPath(), p, 0);
            }
            for (let q = 0; q < f.length; q++) {
                let r = f[q];
                h.add_1(r);
                a.am(a.getCurrentPath(), r, 1);
            }
            for (let s = 0; s < g.length; s++) {
                let t = g[s];
                h.add_1(t);
                a.am(a.getCurrentPath(), t, 2);
            }
            let u = new Array(h.count);
            let v = 0;
            for (let w of fromEnum(h)) {
                u[v] = w;
                v++;
            }
            return u;
        }
        static f(a, b, c) {
            let d = a.getAllPropertiesWithIntent(EnumUtil.getName(DataSeriesIntent_$type, (16)));
            if (d.length > 0) {
                return {
                    ret: d[0],
                    p2: c
                };
            }
            let e = a.getFirstDistinctStringProperty(b);
            c = 1;
            if (e != null) {
                c = 1;
                return {
                    ret: e,
                    p2: c
                };
            }
            e = a.getFirstDistinctMonotonicNumericPropertyWithEvenSpacing(b);
            if (e != null) {
                c = 0.8;
                return {
                    ret: e,
                    p2: c
                };
            }
            e = a.getFirstDistinctMonotonicNumericProperty(b);
            if (e != null) {
                c = 0.7;
                return {
                    ret: e,
                    p2: c
                };
            }
            e = a.getFirstDistinctDateTimeProperty(b);
            if (e != null) {
                c = 0.6;
                return {
                    ret: e,
                    p2: c
                };
            }
            c = 0.6;
            e = a.getFirstStringProperty();
            return {
                ret: e,
                p2: c
            };
        }
        static e(a, b) {
            let c = 1;
            return ((() => { let d = SimplePieSeriesRule.f(a.analyzer, b, c); c = d.p2; return d.ret; })());
        }
        evaluate(a) {
            let b = 1;
            let c = SimplePieSeriesRule.e(a, this.distinctCheckThreshold);
            if (a.adjustPrioritiesBasedOnFitness) {
                b *= this.b;
            }
            let d = null;
            let e = a.analyzer.getAllPropertiesWithIntent(EnumUtil.getName(DataSeriesIntent_$type, (0)));
            if (e.length > 0) {
                d = e;
            }
            if (d == null) {
                d = a.analyzer.getAllNumericProperties();
            }
            if (d == null || d.length == 0) {
                return;
            }
            let f = a.getCurrentDataSource().actualCount;
            if (a.adjustPrioritiesBasedOnFitness && d.length > 0 && d.length < 2 && f > 1 && f < 12) {
                if (this.a(d[0], a)) {
                    b *= 1.1;
                }
            }
            for (let g = 0; g < d.length; g++) {
                if (d[g] == c && d.length > 1) {
                    continue;
                }
                let h = new Array(1);
                h[0] = d[g];
                let i = a.analyzer.getTitleString(null, h);
                let j = new DataSeries();
                let k = new DataSeriesMemberPathHint();
                k.intent = 0;
                k.path = d[g];
                let l = new DataSeriesMemberPathHint();
                l.intent = 16;
                l.path = c;
                j.addMemberPathHint(k);
                j.addMemberPathHint(l);
                j.suggestedSeries = 35;
                this.g(j, a);
                j.suggestedPrimaryAxis = 6;
                j.suggestedSecondaryAxis = 7;
                j.name = d[g];
                if (i != null) {
                    j.title = i;
                }
                else {
                    j.title = d[g];
                    j.title = a.analyzer.expandCamelCasedWords(j.title);
                }
                if (a.adjustPrioritiesBasedOnFitness) {
                    j.priority = truncate(Math.round(this.priority * b));
                }
                a.addDataSeries(j, this);
            }
        }
        a(a, b) {
            return b.analyzer.numericColumnHasDiverseValues(a);
        }
        g(a, b) {
        }
    }
    SimplePieSeriesRule.$t = /*@__PURE__*/ markType(SimplePieSeriesRule, 'SimplePieSeriesRule', Base.$, [IDataSeriesAdapterRule_$type]);
    return SimplePieSeriesRule;
})();
