type Locale = 'en' | 'tr';

const monthNamesByLocale: Record<Locale, string[]> = {
  en: [
    'JANUARY',
    'FEBRUARY',
    'MARCH',
    'APRIL',
    'MAY',
    'JUNE',
    'JULY',
    'AUGUST',
    'SEPTEMBER',
    'OCTOBER',
    'NOVEMBER',
    'DECEMBER'
  ],
  tr: [
    'OCAK',
    'ŞUBAT',
    'MART',
    'NİSAN',
    'MAYIS',
    'HAZİRAN',
    'TEMMUZ',
    'AĞUSTOS',
    'EYLÜL',
    'EKİM',
    'KASIM',
    'ARALIK'
  ]
};

export const formatDateToMonthYear = (
  dateString: string,
  locale: Locale = 'en'
): string => {
  try {
    const date = new Date(dateString);
    const monthNames = monthNamesByLocale[locale];
    const month = monthNames[date.getUTCMonth()];
    const year = date.getUTCFullYear();

    return `${month} ${year}`;
  } catch {
    return dateString;
  }
};
