export interface MonthOption {
  value: string;
  label: string;
}

const monthKeys = [
  "january",
  "february",
  "march",
  "april",
  "may",
  "june",
  "july",
  "august",
  "september",
  "october",
  "november",
  "december",
];

export const getMonthOptions = (
  translate: (key: string) => string
): MonthOption[] => {
  return monthKeys.map((monthKey, index) => ({
    value: String(index + 1),
    label: translate(`months.${monthKey}`),
  }));
};

export const getMonthName = (
  monthNumber: string | number,
  translate: (key: string) => string
): string => {
  const index = Number(monthNumber) - 1;
  const monthKey = monthKeys[index];

  return monthKey ? translate(`months.${monthKey}`) : String(monthNumber);
};

export const getMonthNumber = (
  monthName: string,
  translate: (key: string) => string
): string => {
  const index = monthKeys.findIndex(
    (monthKey) => translate(`months.${monthKey}`) === monthName
  );

  return index !== -1 ? String(index + 1) : monthName;
};
