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