/*
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 { __extends } from "tslib";
import { BuiltInFunctionBase } from "./BuiltInFunctionBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { CalcFunctionUtilities } from "./CalcFunctionUtilities";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { runOn, markType } from "igniteui-angular-core";
import { CalcArgumentHelper } from "./CalcArgumentHelper";
import { truncate, intDivide } from "igniteui-angular-core";
/**
 * @hidden
 */
var UltraCalcFunctionTrimMean = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(UltraCalcFunctionTrimMean, _super);
    function UltraCalcFunctionTrimMean() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionTrimMean.prototype.evaluate = function (a, b) {
        var c = a.pop();
        var d = a.pop();
        if (d.isError) {
            return new ExcelCalcValue(d.toErrorValue());
        }
        if (c.isError) {
            return new ExcelCalcValue(c.toErrorValue());
        }
        var e = c._toDouble3();
        var f = CalcFunctionUtilities.o(10);
        if (e < 0 || e >= 1) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(4));
        }
        try {
            CalcArgumentHelper.c(d, 0, 1229, runOn(f, f.add));
            if (f.count == 0) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(4));
            }
            var g = truncate((e * f.count));
            g -= g % 2;
            if (g > 0) {
                f.y();
            }
            var h = 0;
            for (var i = (intDivide(g, 2)), j = f.count - (intDivide(g, 2)); i < j; i++) {
                h += f._inner[i];
            }
            var k = CalcFunctionUtilities.t(f.count - g, h);
            return new ExcelCalcValue(k);
        }
        finally {
            CalcFunctionUtilities.ac(f);
        }
    };
    UltraCalcFunctionTrimMean.prototype.get_name = function () {
        return "trimmean";
    };
    Object.defineProperty(UltraCalcFunctionTrimMean.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionTrimMean.prototype.get_minArgs = function () {
        return 2;
    };
    Object.defineProperty(UltraCalcFunctionTrimMean.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionTrimMean.prototype.get_maxArgs = function () {
        return 2;
    };
    Object.defineProperty(UltraCalcFunctionTrimMean.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionTrimMean.$t = markType(UltraCalcFunctionTrimMean, 'UltraCalcFunctionTrimMean', BuiltInFunctionBase.$);
    return UltraCalcFunctionTrimMean;
}(BuiltInFunctionBase));
export { UltraCalcFunctionTrimMean };
