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

export function getRange(dateParam, viewParam) {
  let start, end;
  let date = dateParam || new Date();
  let view = viewParam || "week";
  // if view is day: from dayjs(date).startOf('day') to dayjs(date).endOf('day');
  if (view === "day") {
    start = dayjs(date).startOf("day");
    end = dayjs(date).endOf("day");
  }
  // if view is week: from dayjs(date).startOf('isoWeek') to dayjs(date).endOf('isoWeek');
  else if (view === "week") {
    start = dayjs(date).startOf("week");
    end = dayjs(date).endOf("week");
  }
  //if view is month: from dayjs(date).startOf('month').subtract(7, 'day') to dayjs(date).endOf('month').add(7, 'day'); i do additional 7 days math because you can see adjacent weeks on month view (that is the way how i generate my recurrent events for the Big Calendar, but if you need only start-end of month - just remove that math);
  else if (view === "month") {
    start = dayjs(date).startOf("month").subtract(7, "day");
    end = dayjs(date).endOf("month").add(7, "day");
  }
  // if view is agenda: from dayjs(date).startOf('day') to dayjs(date).endOf('day').add(1, 'month');
  else if (view === "agenda") {
    start = dayjs(date).startOf("day");
    end = dayjs(date).endOf("day").add(1, "month");
  }

  return { start, end };
}
