import 'package:timeago/timeago.dart' as timeago;

import 'package:pweb/generated/i18n/app_localizations.dart'; // Ensure this file exports supportedLocales

// Mapping of language codes to timeago message classes.
final Map<String, timeago.LookupMessages> _timeagoLocales = {
  'en': timeago.EnMessages(),
  'ru': timeago.RuMessages(),
  'uk': timeago.UkMessages(),
  // Add more mappings as needed.
};

/// Initializes timeago using the supported locales from AppLocalisations.
/// Optionally, [defaultLocale] can be set (defaults to 'en').
void initializeTimeagoLocales({String defaultLocale = 'en'}) {
  // Assume AppLocalisations.supportedLocales is a static List<Locale>
  final supportedLocales = AppLocalizations.supportedLocales;
  
  for (final locale in supportedLocales) {
    final languageCode = locale.languageCode;
    if (_timeagoLocales.containsKey(languageCode)) {
      timeago.setLocaleMessages(languageCode, _timeagoLocales[languageCode]!);
    }
  }
  // Set the default locale.
  timeago.setDefaultLocale(defaultLocale);
}
