import moment from "moment";

export function isSameDate(dateA: Date, dateB: Date) {
    const date1 = moment(dateA).format('YYYY-MM-DD');
    const date2 = moment(dateB).format('YYYY-MM-DD');

    return date1 === date2;
}

export function extractTime(date: Date): string {
    return moment(date).format("HH:mm");
}

export function extractDate(date: Date): string {
    return moment(date).format("DD.MM.YYYY");
}

export function getTimeSlots(startDate: string, startTime: string, endTime: string, intervalMinutes: number = 15) {
    let start = moment(`${startDate} ${startTime}`, "YYYY-MM-DD HH:mm");
    let end = moment(`${startDate} ${endTime}`, "YYYY-MM-DD HH:mm");
    let timeSlots = [];

    while (start <= end) {
        if (start.clone().add(intervalMinutes, "minutes").isAfter(end)) {
            break; // Ensures the last slot does not exceed end time
        }

        timeSlots.push(start.format("YYYY-MM-DDTHH:mm")); // ISO-like format
        start.add(intervalMinutes, "minutes");
    }

    return timeSlots;
}

export function isDueDatePassed(dueDate: Date) {
    return moment(dueDate).isBefore();
}