"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAttendanceToday = isAttendanceToday;
exports.isGroupedPresent = isGroupedPresent;
exports.classifyIndividualSummaryBucket = classifyIndividualSummaryBucket;
exports.isGroupedAbsent = isGroupedAbsent;
exports.classifyMemberMonthSummaryField = classifyMemberMonthSummaryField;
exports.countGroupedPresentRecords = countGroupedPresentRecords;
const helpers_1 = require("./helpers");
const IN_PROGRESS_STATUSES = ['check_in', 'on_break'];
const SKIP_STATUSES = ['weekend', 'holiday'];
function isAttendanceToday(date, todayStartUtc, todayEndUtc) {
    const attendanceDate = new Date(date);
    return attendanceDate >= todayStartUtc && attendanceDate <= todayEndUtc;
}
function isGroupedPresent(status, isToday) {
    if (isToday) {
        return helpers_1.attendancePresentStatuses.includes(status);
    }
    return helpers_1.attendancePastPresentStatuses.includes(status);
}
function classifyIndividualSummaryBucket(status, isToday) {
    if (SKIP_STATUSES.includes(status)) {
        return 'skip';
    }
    if (status === 'on_leave') {
        return 'leave';
    }
    if (status === 'absent') {
        return 'absent';
    }
    if (status === 'late') {
        return 'late';
    }
    if (status === 'half_day') {
        return 'half_day';
    }
    if (status === 'present' || status === 'remote') {
        return 'present';
    }
    if (IN_PROGRESS_STATUSES.includes(status)) {
        return isToday ? 'present' : 'absent';
    }
    return 'skip';
}
function isGroupedAbsent(status, isToday) {
    if (status === 'absent') {
        return true;
    }
    if (!isToday && IN_PROGRESS_STATUSES.includes(status)) {
        return true;
    }
    return false;
}
function classifyMemberMonthSummaryField(status, isToday) {
    if (SKIP_STATUSES.includes(status)) {
        return 'skip';
    }
    if (status === 'on_leave') {
        return 'total_leave';
    }
    if (status === 'absent') {
        return 'total_absent';
    }
    if (status === 'late') {
        return 'total_late';
    }
    if (status === 'present' ||
        status === 'remote' ||
        status === 'half_day') {
        return 'total_present';
    }
    if (IN_PROGRESS_STATUSES.includes(status)) {
        return isToday ? 'total_present' : 'total_absent';
    }
    return 'skip';
}
function countGroupedPresentRecords(records, todayStartUtc, todayEndUtc) {
    return records.filter((record) => isGroupedPresent(record.status, isAttendanceToday(record.date, todayStartUtc, todayEndUtc))).length;
}
//# sourceMappingURL=attendance-summary.util.js.map