import moment from "moment";

export const filterEmployees = (values: any, dataMode: string = 'month', excludePast: boolean = false, month: number) => {
    let today = moment()
    const day = moment().format("D");
    const numberMonth = Number(moment().format("M"))-1
 
    let employee = values
        .map((val: any, index: number) => {
            if (index == 0) {
                return;
            }
            return {
                day: Number(val[0]),
                name: val[1],
                position: val[2],
                image: val[3],
                optional: val[4],
                month
            };
        })
        .filter((val: any) => val !== undefined);

    if (dataMode == "daily")
        employee = employee.filter((contract: any) => contract.day == day);
    if (dataMode == "weekly")
        employee = employee.filter(
            (contract: any) => {
                let bdayDate = moment([today.year(), contract.month, contract.day])
                return bdayDate.isoWeek() === today.isoWeek()
            }
        );

    employee.sort((a: any, b: any) => {
        if (a.day < b.day) return -1
        else if (a.day === b.day) return 0
        else return 1
    })

    if (excludePast && (numberMonth >= month))
        employee = employee.filter((contract: any) => (contract.day >= day && contract.month >=numberMonth))

    return employee
}