"use strict";
const dayjs = require("dayjs");
const RANGE = {
  TODAY: "Today",
  YESTERDAY: "Yesterday",
  THIS_WEEK: "This Week",
  PREVIOUS_WEEK: "Previous Week",
  THIS_MONTH: "This Month",
  PREVIOUS_MONTH: "Previous Month",
  THIS_QUARTER: "This Quarter",
  PREVIOUS_QUARTER: "Previous Quarter",
  THIS_YEAR: "This Year",
  PREVIOUS_YEAR: "Previous Year",
  CUSTOM: "Custom"
};
const handleCompareDateRange = async (params) => {
  const { range, from = "", to = "" } = params;
  const today = dayjs();
  let startDate;
  let endDate;
  switch (range) {
    case RANGE.TODAY:
      startDate = today.startOf("day");
      endDate = today.endOf("day");
      break;
    case RANGE.YESTERDAY:
      startDate = today.subtract(1, "day").startOf("day");
      endDate = today.subtract(1, "day").endOf("day");
      break;
    case RANGE.THIS_WEEK:
      startDate = today.startOf("week");
      endDate = today.endOf("week");
      break;
    case RANGE.PREVIOUS_WEEK:
      startDate = today.subtract(1, "week").startOf("week");
      endDate = today.subtract(1, "week").endOf("week");
      break;
    case RANGE.THIS_MONTH:
      startDate = today.startOf("month");
      endDate = today.endOf("month");
      break;
    case RANGE.PREVIOUS_MONTH:
      startDate = today.subtract(1, "month").startOf("month");
      endDate = today.subtract(1, "month").endOf("month");
      break;
    case RANGE.THIS_QUARTER:
      const currentQuarter = Math.floor(today.month() / 3);
      startDate = today.month(currentQuarter * 3).startOf("month");
      endDate = today.month(currentQuarter * 3 + 2).endOf("month");
      break;
    case RANGE.PREVIOUS_QUARTER:
      const prevQuarter = Math.floor(today.month() / 3) - 1;
      startDate = today.month(prevQuarter * 3).startOf("month");
      endDate = today.month(prevQuarter * 3 + 2).endOf("month");
      break;
    case RANGE.THIS_YEAR:
      startDate = today.startOf("year");
      endDate = today.endOf("year");
      break;
    case RANGE.PREVIOUS_YEAR:
      startDate = today.subtract(1, "year").startOf("year");
      endDate = today.subtract(1, "year").endOf("year");
      break;
    case RANGE.CUSTOM:
      startDate = from ? dayjs(from) : today.startOf("day");
      endDate = to ? dayjs(to) : today.endOf("day");
      break;
    default:
      startDate = today.startOf("day");
      endDate = today.endOf("day");
  }
  return {
    from: startDate.format("YYYY-MM-DD"),
    to: endDate.format("YYYY-MM-DD")
  };
};
const handleCompareDateRangeSync = (params) => {
  const { range, from = "", to = "" } = params;
  const today = dayjs();
  let startDate;
  let endDate;
  switch (range) {
    case RANGE.TODAY:
      startDate = today.startOf("day");
      endDate = today.endOf("day");
      break;
    case RANGE.YESTERDAY:
      startDate = today.subtract(1, "day").startOf("day");
      endDate = today.subtract(1, "day").endOf("day");
      break;
    case RANGE.THIS_WEEK:
      startDate = today.startOf("week");
      endDate = today.endOf("week");
      break;
    case RANGE.PREVIOUS_WEEK:
      startDate = today.subtract(1, "week").startOf("week");
      endDate = today.subtract(1, "week").endOf("week");
      break;
    case RANGE.THIS_MONTH:
      startDate = today.startOf("month");
      endDate = today.endOf("month");
      break;
    case RANGE.PREVIOUS_MONTH:
      startDate = today.subtract(1, "month").startOf("month");
      endDate = today.subtract(1, "month").endOf("month");
      break;
    case RANGE.THIS_QUARTER:
      const currentQuarter = Math.floor(today.month() / 3);
      startDate = today.month(currentQuarter * 3).startOf("month");
      endDate = today.month(currentQuarter * 3 + 2).endOf("month");
      break;
    case RANGE.PREVIOUS_QUARTER:
      const prevQuarter = Math.floor(today.month() / 3) - 1;
      startDate = today.month(prevQuarter * 3).startOf("month");
      endDate = today.month(prevQuarter * 3 + 2).endOf("month");
      break;
    case RANGE.THIS_YEAR:
      startDate = today.startOf("year");
      endDate = today.endOf("year");
      break;
    case RANGE.PREVIOUS_YEAR:
      startDate = today.subtract(1, "year").startOf("year");
      endDate = today.subtract(1, "year").endOf("year");
      break;
    case RANGE.CUSTOM:
      startDate = from ? dayjs(from) : today.startOf("day");
      endDate = to ? dayjs(to) : today.endOf("day");
      break;
    default:
      startDate = today.startOf("day");
      endDate = today.endOf("day");
  }
  return {
    from: startDate.format("YYYY-MM-DD"),
    to: endDate.format("YYYY-MM-DD")
  };
};
const navigateWithId = (navigate, routePath, id, fallbackState) => {
  const path = routePath.replace(":id", id.toString());
  navigate(path, fallbackState ? { state: fallbackState } : void 0);
};
const getEntityId = (params, location, idField = "id") => {
  if (params.id) {
    return params.id;
  }
  if (location.state && location.state[idField]) {
    return location.state[idField].toString();
  }
  return void 0;
};
exports.RANGE = RANGE;
exports.getEntityId = getEntityId;
exports.handleCompareDateRange = handleCompareDateRange;
exports.handleCompareDateRangeSync = handleCompareDateRangeSync;
exports.navigateWithId = navigateWithId;
//# sourceMappingURL=navigation-utils-CjGqJQmS.js.map
