import { isBefore, startOfYear, addMonths, format, startOfMonth, isAfter, endOfMonth, addYears } from "date-fns";
function minMaxCheckThrow(min, max) {
  if (min && max && isBefore(max, min)) {
    throw new Error(`Min date cannot be before max date!`);
  }
}
function getMonths(forYear, locale, min, max) {
  minMaxCheckThrow(min, max);
  const firstMonth = startOfYear(new Date(forYear, 1, 1));
  const months = [];
  for (let i = 0; i < 12; i += 1) {
    const currentDate = i === 0 ? firstMonth : addMonths(firstMonth, i);
    months.push({
      index: i,
      name: format(currentDate, "MMMM", { locale }),
      disabled: !!min && isBefore(currentDate, startOfMonth(min)) || !!max && isAfter(currentDate, endOfMonth(max))
    });
  }
  return months;
}
function getYears(min, max) {
  minMaxCheckThrow(min, max);
  let currentYear = min ? startOfYear(min) : new Date(1900, 1, 1);
  const years = [];
  while (currentYear.getFullYear() <= ((max == null ? void 0 : max.getFullYear()) ?? 2100)) {
    years.push(currentYear.getFullYear());
    currentYear = addYears(currentYear, 1);
  }
  return years;
}
function formatDate(incomingDate, formatString) {
  return incomingDate ? format(incomingDate, formatString) : void 0;
}
export {
  formatDate,
  getMonths,
  getYears,
  minMaxCheckThrow
};
//# sourceMappingURL=dateTimeInput.utils.js.map
