/*
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 { BuiltInFunctionBase } from "./BuiltInFunctionBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { Base, markType } from "igniteui-angular-core";
/**
 * @hidden
 */
export let UltraCalcFunctionRankBase = /*@__PURE__*/ (() => {
    class UltraCalcFunctionRankBase extends BuiltInFunctionBase {
        static _ak(a, b, c) {
            let d = true;
            if (b == 3) {
                let e = a.pop();
                d = !e._toBoolean1();
            }
            let f = a.pop();
            let g = a.pop();
            if (g.isError) {
                return new ExcelCalcValue(g.toErrorValue());
            }
            let h = g._toDouble3();
            let i = f.toArrayProxy();
            let j = i.getLength(0);
            let k = i.getLength(1);
            let l, m, n;
            l = m = n = 0;
            for (let o = 0; o < j; o++) {
                for (let p = 0; p < k; p++) {
                    let q = i.item(o, p);
                    if (q.isError) {
                        return new ExcelCalcValue(q.toErrorValue());
                    }
                    if (q.isNull || q.isString || q.isBoolean) {
                        l++;
                    }
                    else {
                        let r = Base.compareSimple(h, q._toDouble3());
                        if (r < 0) {
                            m++;
                        }
                        else if (r == 0) {
                            n++;
                        }
                    }
                }
            }
            if (n == 0) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(3));
            }
            let s = !d ? (k * j) - (l + m + n) : m;
            let t = s + 1;
            if (c) {
                t += (n - 1) / 2;
            }
            return new ExcelCalcValue(t);
        }
        get_maxArgs() {
            return 3;
        }
        get maxArgs() {
            return this.get_maxArgs();
        }
        get_minArgs() {
            return 2;
        }
        get minArgs() {
            return this.get_minArgs();
        }
    }
    UltraCalcFunctionRankBase.$t = markType(UltraCalcFunctionRankBase, 'UltraCalcFunctionRankBase', BuiltInFunctionBase.$);
    return UltraCalcFunctionRankBase;
})();
