export const rangeSelectorTypes = [
  { id: "custom", value: "custom", label: "Custom" },
  { id: "last7Days", value: "last7Days", label: "Last 7 Days" },
  { id: "week", value: "week", label: "Week" },
  { id: "month", value: "month", label: "Month" },
  { id: "quarter", value: "quarter", label: "Quarter" },
  { id: "year", value: "year", label: "Year" },
];

export const setStartDateOffset = (selectedRange, day) => {
  switch (selectedRange) {
    case "last7Days":
      return day.subtract(7, "days");

    case "week":
      return day.startOf("week");

    case "month":
      return day.startOf("month");

    case "quarter":
      return day.startOf("quarter");

    case "year":
      return day.startOf("year");
  }
};
export const setEndDateOffset = (selectedRange, day) => {
  switch (selectedRange) {
    case "last7Days":
      return day.subtract(0, "days");

    case "week":
      return day.endOf("week");

    case "month":
      return day.endOf("month");

    case "quarter":
      return day.endOf("quarter");

    case "year":
      return day.endOf("year");
  }
};

export const calculatePosition = ({
  containerRef,
  setCustomPosition,
  showRangeSelector,
}) => {
  const containerPos = containerRef?.current?.getBoundingClientRect();
  if (!containerPos) return;

  const { x } = containerPos;
  const innerWidth = window.innerWidth;

  const threshold = showRangeSelector ? 550 : 450;
  const availableSpace = innerWidth - x - 20;

  if (availableSpace < threshold) {
    setCustomPosition({
      left: "auto",
      right: 0,
    });
  }
};

export const formatMomentDate = (date, dateFormat = "YYYY-MM-DD") => {
  return date?.format(dateFormat);
};
