import dayjs from "../../utils/day";

export const CalculateWorkingDaysThisMonth = () => dayjs().endOf("month").businessDaysInMonth().length;

export const CalculateWorkingDaysInPeriod = (start, end) => dayjs(end).businessDiff(dayjs(start));

export const CalculateWorkingDaysAsOfToday = () => dayjs().businessDaysInMonth().length;

export const CalculateWorkingDaysLastMonth = () =>
  dayjs().subtract(1, "month").endOf("month").businessDaysInMonth().length;

export const WeeklyTargetHrs = (dailyTargetHrs) =>
  dailyTargetHrs * CalculateWorkingDaysInPeriod(dayjs().startOf("week"), dayjs().endOf("week"));

export const WeeklyTargetHrsInPeriod = (dailyTargetHrs, start, end) =>
  dailyTargetHrs * CalculateWorkingDaysInPeriod(start, end);

export const MonthlyTargetHrs = (dailyTargetHrs) => dailyTargetHrs * CalculateWorkingDaysThisMonth();

export const LastMonthTargetHrs = (dailyTargetHrs) => dailyTargetHrs * CalculateWorkingDaysLastMonth();

export const AsOfTodayTargetHrs = (dailyTargetHrs) => dailyTargetHrs * CalculateWorkingDaysAsOfToday();

export const AsOfDateTargetHours = (dailyTargetHours, date) =>
  dailyTargetHours * dayjs(date).businessDiff(dayjs().startOf("month"));

export const ListOfDaysInCurrentMonth = () => {
  const days = [];
  let dateStart = dayjs().startOf("month");
  const dateEnd = dayjs().endOf("month");
  while (dateEnd.diff(dateStart, "day") > 0) {
    days.push(dateStart.format("YYYY-MM-DD"));
    dateStart = dateStart.add(1, "day");
  }
  days.push(dateEnd.format("YYYY-MM-DD"));
  return days;
};

export const ListDaysBetween = ({ start, end }) => {
  const days = [];
  let dateStart = dayjs(start);
  const dateEnd = dayjs(end);
  while (dateEnd.diff(dateStart, "day") >= 0) {
    days.push(dateStart.format("YYYY-MM-DD"));
    dateStart = dateStart.add(1, "day");
  }
  return days;
};
