"use strict";

/**
 * Language utilities for OxyServices
 * Provides access to supported languages and language metadata
 */

// Supported languages with their metadata
export const SUPPORTED_LANGUAGES = [{
  id: 'en-US',
  name: 'English',
  nativeName: 'English',
  flag: '🇺🇸',
  icon: 'language-outline',
  color: '#007AFF'
}, {
  id: 'es-ES',
  name: 'Spanish',
  nativeName: 'Español',
  flag: '🇪🇸',
  icon: 'language-outline',
  color: '#FF3B30'
}, {
  id: 'ca-ES',
  name: 'Catalan',
  nativeName: 'Català',
  flag: '🇪🇸',
  icon: 'language-outline',
  color: '#0CA678'
}, {
  id: 'fr-FR',
  name: 'French',
  nativeName: 'Français',
  flag: '🇫🇷',
  icon: 'language-outline',
  color: '#5856D6'
}, {
  id: 'de-DE',
  name: 'German',
  nativeName: 'Deutsch',
  flag: '🇩🇪',
  icon: 'language-outline',
  color: '#FF9500'
}, {
  id: 'it-IT',
  name: 'Italian',
  nativeName: 'Italiano',
  flag: '🇮🇹',
  icon: 'language-outline',
  color: '#34C759'
}, {
  id: 'pt-PT',
  name: 'Portuguese',
  nativeName: 'Português',
  flag: '🇵🇹',
  icon: 'language-outline',
  color: '#AF52DE'
}, {
  id: 'ja-JP',
  name: 'Japanese',
  nativeName: '日本語',
  flag: '🇯🇵',
  icon: 'language-outline',
  color: '#FF2D92'
}, {
  id: 'ko-KR',
  name: 'Korean',
  nativeName: '한국어',
  flag: '🇰🇷',
  icon: 'language-outline',
  color: '#32D74B'
}, {
  id: 'zh-CN',
  name: 'Chinese',
  nativeName: '中文',
  flag: '🇨🇳',
  icon: 'language-outline',
  color: '#FF9F0A'
}, {
  id: 'ar-SA',
  name: 'Arabic',
  nativeName: 'العربية',
  flag: '🇸🇦',
  icon: 'language-outline',
  color: '#30B0C7'
}];
const FALLBACK_LANGUAGE = 'en-US';

/**
 * Get language metadata by language code
 * @param languageCode - BCP-47 language code (e.g., 'en-US', 'es-ES')
 * @returns Language metadata or null if not found
 */
export function getLanguageMetadata(languageCode) {
  if (!languageCode) return null;

  // Direct match
  const exactMatch = SUPPORTED_LANGUAGES.find(lang => lang.id === languageCode);
  if (exactMatch) return exactMatch;

  // Try to match base language code (e.g., 'en' matches 'en-US')
  const baseCode = languageCode.split('-')[0];
  const baseMatch = SUPPORTED_LANGUAGES.find(lang => lang.id.startsWith(baseCode + '-'));
  if (baseMatch) return baseMatch;
  return null;
}

/**
 * Get language name by language code
 * @param languageCode - BCP-47 language code (e.g., 'en-US', 'es-ES')
 * @returns Language name (e.g., 'English') or the code if not found
 */
export function getLanguageName(languageCode) {
  const metadata = getLanguageMetadata(languageCode);
  return metadata?.name || languageCode || FALLBACK_LANGUAGE;
}

/**
 * Get native language name by language code
 * @param languageCode - BCP-47 language code (e.g., 'en-US', 'es-ES')
 * @returns Native language name (e.g., 'Español') or the code if not found
 */
export function getNativeLanguageName(languageCode) {
  const metadata = getLanguageMetadata(languageCode);
  return metadata?.nativeName || languageCode || FALLBACK_LANGUAGE;
}

/**
 * Normalize language code to BCP-47 format
 * @param lang - Language code (may be short like 'en' or full like 'en-US')
 * @returns Normalized BCP-47 language code
 */
export function normalizeLanguageCode(lang) {
  if (!lang) return FALLBACK_LANGUAGE;
  if (lang.includes('-')) return lang;
  const map = {
    en: 'en-US',
    es: 'es-ES',
    ca: 'ca-ES',
    fr: 'fr-FR',
    de: 'de-DE',
    it: 'it-IT',
    pt: 'pt-PT',
    ja: 'ja-JP',
    ko: 'ko-KR',
    zh: 'zh-CN',
    ar: 'ar-SA'
  };
  return map[lang] || lang;
}
//# sourceMappingURL=languageUtils.js.map