import { parseStringDate } from 'apps/sales/src/app/modules/task-calendar/utils';

export function taskIsAllDay(timeFrom: string, timeTo: string, numberOfHoursAllDay: number = 8): boolean {
  const startDate = parseStringDate(timeFrom);
  const endDate = parseStringDate(timeTo);

  if (!timeTo) {
    return true;
  }

  if (!isSameYear(startDate, endDate)) {
    return false;
  }

  if (!isSameMonth(startDate, endDate)) {
    return false;
  }

  if (!isSameDay(startDate, endDate)) {
    return false;
  }

  return endDate.getHours() - startDate.getHours() > numberOfHoursAllDay ? true : false;
}

export function taskIsMultiDay(timeFrom: string, timeTo: string): boolean {
  if (!timeFrom || !timeTo) {
    return false;
  }

  const startDate = parseStringDate(timeFrom);
  const endDate = parseStringDate(timeTo);

  return !isSameDay(startDate, endDate) && startDate <= endDate;
}

export function isSameYear(date1: Date, date2: Date): boolean {
  return date1.getFullYear() === date2.getFullYear();
}

export function isSameMonth(date1: Date, date2: Date): boolean {
  return date1.getMonth() === date2.getMonth();
}

export function isSameDay(date1: Date, date2: Date): boolean {
  return date1.getDate() === date2.getDate();
}
