/*
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 { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { markType } from "igniteui-angular-core";
import { dateGetDate, dateFromValues, dateAddDays } from "igniteui-angular-core";
/**
 * @hidden
 */
var UltraCalcFunctionWeekDay = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(UltraCalcFunctionWeekDay, _super);
    function UltraCalcFunctionWeekDay() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionWeekDay.prototype.evaluate = function (a, b) {
        var c = (b == 2) ? a.pop()._toInt321() : 1;
        var d = dateGetDate(a.pop()._toDateTime1());
        if (true) {
            if (d <= dateFromValues(1900, 3, 1, 0, 0, 0, 0)) {
                d = dateAddDays(d, -1);
            }
        }
        var e = d.getDay();
        var f = e;
        switch (c) {
            case 1:
                f++;
                break;
            case 2:
                if (e == 0) {
                    f += 7;
                }
                break;
            case 3:
                f += (e != 0) ? -1 : 6;
                break;
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
                f = (f + 7 - (c - 10)) % 7 + 1;
                break;
            default: return new ExcelCalcValue(new ExcelCalcErrorValue(4));
        }
        return new ExcelCalcValue(f);
    };
    UltraCalcFunctionWeekDay.prototype.get_name = function () {
        return "weekday";
    };
    Object.defineProperty(UltraCalcFunctionWeekDay.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionWeekDay.prototype.get_minArgs = function () {
        return 1;
    };
    Object.defineProperty(UltraCalcFunctionWeekDay.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionWeekDay.prototype.get_maxArgs = function () {
        return 2;
    };
    Object.defineProperty(UltraCalcFunctionWeekDay.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: false,
        configurable: true
    });
    UltraCalcFunctionWeekDay.prototype.doesParameterAllowIntermediateResultArray = function (a, b) {
        return true;
    };
    UltraCalcFunctionWeekDay.$t = markType(UltraCalcFunctionWeekDay, 'UltraCalcFunctionWeekDay', BuiltInFunctionBase.$);
    return UltraCalcFunctionWeekDay;
}(BuiltInFunctionBase));
export { UltraCalcFunctionWeekDay };
