/*
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 { fromEnum, markType } from "igniteui-angular-core";
import { UltraCalcFunctionWorkDay } from "./UltraCalcFunctionWorkDay";
import { UltraCalcFunctionDateDiff } from "./UltraCalcFunctionDateDiff";
import { intDivide } from "igniteui-angular-core";
import { dateGetDate } from "igniteui-angular-core";
/**
 * @hidden
 */
export class UltraCalcFunctionNetWorkDays 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 = dateGetDate(a.pop()._toDateTime1());
        let h = dateGetDate(a.pop()._toDateTime1());
        let i = 1;
        if (h > g) {
            i = -1;
            let j = h;
            h = g;
            g = j;
        }
        let k = UltraCalcFunctionDateDiff._am(a._w, 4, h, g);
        k += 1;
        if (k > 0) {
            let l = (intDivide(k, 7));
            let m = (k % 7);
            k -= (l * 2);
            switch (h.getDay()) {
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                    let n = 8 - h.getDay();
                    if (m >= n) {
                        k -= Math.min(2, n);
                    }
                    else if (m == (n - 1)) {
                        k -= Math.min(1, n);
                    }
                    break;
                case 0:
                    if (m >= 1) {
                        k -= 1;
                    }
                    break;
                default: break;
            }
            if (d != null) {
                for (let o of fromEnum(d.keys)) {
                    if (o >= h && o <= g) {
                        k -= 1;
                    }
                }
            }
            k *= i;
        }
        return new ExcelCalcValue(k);
    }
    canParameterBeEnumerable(a) {
        return a == 2;
    }
    get_name() {
        return "networkdays";
    }
    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();
    }
}
UltraCalcFunctionNetWorkDays.$t = markType(UltraCalcFunctionNetWorkDays, 'UltraCalcFunctionNetWorkDays', BuiltInFunctionBase.$);
//# sourceMappingURL=UltraCalcFunctionNetWorkDays.js.map