/*
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 { Dictionary$2 } from "igniteui-angular-core";
import { Base, Date_$type, markType } from "igniteui-angular-core";
import { dateGetDate, dateAddDays } from "igniteui-angular-core";
/**
 * @hidden
 */
export class UltraCalcFunctionWorkDay extends BuiltInFunctionBase {
    evaluate(a, b) {
        let c = this._getArguments(a, b - 2, true);
        let d;
        let e;
        let f = ((() => { let g = UltraCalcFunctionWorkDay._ak(c, d, e); d = g.p1; e = g.p2; return g.ret; })());
        if (f == false) {
            return e;
        }
        let g = a.pop()._toInt321();
        let h = dateGetDate(a.pop()._toDateTime1());
        let i = h;
        let j = Math.abs(g);
        let k = 0;
        if (g != 0) {
            let l = g < 0 ? -1 : 1;
            do {
                i = dateAddDays(i, l);
                k += this._an(i, d) ? 1 : 0;
            } while (k < j);
        }
        return new ExcelCalcValue(i);
    }
    canParameterBeEnumerable(a) {
        return a == 2;
    }
    _an(a, b) {
        if (UltraCalcFunctionWorkDay._al(a)) {
            return false;
        }
        if (b != null && b.containsKey(a)) {
            return false;
        }
        return true;
    }
    get_name() {
        return "workday";
    }
    get name() {
        return this.get_name();
    }
    get_minArgs() {
        return 2;
    }
    get minArgs() {
        return this.get_minArgs();
    }
    get_maxArgs() {
        return 3;
    }
    get maxArgs() {
        return this.get_maxArgs();
    }
    static _ak(a, b, c) {
        if (a.length > 0) {
            b = new Dictionary$2(Date_$type, Base.$, 1, a.length);
            for (let e = 0; e < a.length; e++) {
                let d = a[e];
                if (d.isError) {
                    c = new ExcelCalcValue(d.toErrorValue());
                    return {
                        ret: false,
                        p1: b,
                        p2: c
                    };
                }
                let f = dateGetDate(d._toDateTime1());
                if (UltraCalcFunctionWorkDay._al(f) == false) {
                    if (b.containsKey(f) == false) {
                        b.addItem(f, null);
                    }
                }
            }
        }
        else {
            b = null;
        }
        c = null;
        return {
            ret: true,
            p1: b,
            p2: c
        };
    }
    static _al(a) {
        return UltraCalcFunctionWorkDay._am(a.getDay());
    }
    static _am(a) {
        return a == 6 || a == 0;
    }
    doesParameterAllowIntermediateResultArray(a, b) {
        return (b == false);
    }
}
UltraCalcFunctionWorkDay.$t = markType(UltraCalcFunctionWorkDay, 'UltraCalcFunctionWorkDay', BuiltInFunctionBase.$);
//# sourceMappingURL=UltraCalcFunctionWorkDay.js.map