// Internationalization Setup

import { getLocales } from 'expo-localization';

type IntlConfig = {
  enableHighAccuracy: boolean;
  fallbackLocale: string;
  supportedLocales: string[];
};

const intlConfig: IntlConfig = {
  enableHighAccuracy: true,
  fallbackLocale: 'en',
  supportedLocales: ['en', 'es', 'fr', 'de', 'ja', 'ko', 'zh'],
};

export const locales = {
  en: {
    name: 'English',
    strings: {
      'app.name': 'Rssuper',
      'tab.home': 'Home',
      'tab.explore': 'Explore',
      'tab.settings': 'Settings',
      'feed.add': 'Add Feed',
      'feed.loading': 'Loading feeds...',
      'feed.error': 'Error loading feed',
      'feed.noItems': 'No items in this feed',
      'explore.discover': 'Discover new feeds and podcasts',
      'explore.searchPlaceholder': 'Search feeds, topics, podcasts',
      'explore.all': 'All',
      'explore.trending': 'Trending Feeds',
      'explore.recommended': 'Recommended Podcasts',
      'explore.noFeeds': 'No feeds found matching your criteria',
      'common.cancel': 'Cancel',
      'common.save': 'Save',
      'common.delete': 'Delete',
      'common.edit': 'Edit',
    },
  },
  es: {
    name: 'Espa\u00f1ol',
    strings: {
      'app.name': 'Rssuper',
      'tab.home': 'Inicio',
      'tab.explore': 'Explorar',
      'tab.settings': 'Ajustes',
      'feed.add': 'A\u00f1adir Feed',
      'feed.loading': 'Cargando feeds...',
      'feed.error': 'Error cargando feed',
      'feed.noItems': 'No hay items en este feed',
      'explore.discover': 'Descubre nuevos feeds y podcasts',
      'explore.searchPlaceholder': 'Buscar feeds, temas, podcasts',
      'explore.all': 'Todo',
      'explore.trending': 'Feeds en tendencia',
      'explore.recommended': 'Podcasts recomendados',
      'explore.noFeeds': 'No se encontraron feeds',
      'common.cancel': 'Cancelar',
      'common.save': 'Guardar',
      'common.delete': 'Eliminar',
      'common.edit': 'Editar',
    },
  },
  fr: {
    name: 'Fran\u00e7ais',
    strings: {
      'app.name': 'Rssuper',
      'tab.home': 'Accueil',
      'tab.explore': 'Explorer',
      'tab.settings': 'Paramètres',
      'feed.add': 'Ajouter un flux',
      'feed.loading': 'Chargement des flux...',
      'feed.error': 'Erreur de chargement',
      'feed.noItems': 'Aucun \u00e9l\u00e9ment dans ce flux',
      'explore.discover': 'D\u00e9couvrez de nouveaux flux et podcasts',
      'explore.searchPlaceholder': 'Rechercher des flux, th\u00e8mes, podcasts',
      'explore.all': 'Tout',
      'explore.trending': 'Flux tendances',
      'explore.recommended': 'Podcasts recommand\u00e9s',
      'explore.noFeeds': 'Aucun flux trouv\u00e9',
      'common.cancel': 'Annuler',
      'common.save': 'Enregistrer',
      'common.delete': 'Supprimer',
      'common.edit': 'Modifier',
    },
  },
  // Add more languages as needed
};

export function t(key: string, locale?: string): string {
  const currentLocale = locale || getLocales()[0]?.languageTag?.split('-')[0] || 'en';
  const localeData = locales[currentLocale as keyof typeof locales];
  
  if (!localeData) return key;
  
  return localeData.strings[key as keyof typeof localeData.strings] || key;
}

export function useTranslation() {
  const currentLocale = getLocales()[0]?.languageTag?.split('-')[0] || 'en';
  
  return {
    t: (key: string) => t(key, currentLocale),
    locale: currentLocale,
    locales: Object.entries(locales).map(([code, data]) => ({
      code,
      name: data.name,
    })),
  };
}

export { intlConfig };
export default intlConfig;
