// #region Languages [C:1] [TYPE Data] [SEMANTICS i18n, languages, constants]
// @BRIEF Shared constant mapping BCP-47 language codes → display names in English.
// Used everywhere language selection is exposed — ConfigTabForm, dictionary detail,
// settings language picker, and translation job config.
//
// SOURCE OF TRUTH for the full set of languages known to the application.
// The subset of *allowed* languages is configured via GlobalSettings.allowed_languages.

export const LANGUAGE_LABELS: Record<string, string> = {
  ru: 'Русский',
  en: 'English',
  de: 'Deutsch',
  fr: 'Français',
  es: 'Español',
  it: 'Italiano',
  pt: 'Português',
  zh: '中文',
  ja: '日本語',
  ko: '한국어',
  ar: 'العربية',
  tr: 'Türkçe',
  nl: 'Nederlands',
  pl: 'Polski',
  sv: 'Svenska',
  da: 'Dansk',
  fi: 'Suomi',
  cs: 'Čeština',
  hu: 'Magyar',
  ro: 'Română',
  vi: 'Tiếng Việt',
  th: 'ไทย',
  he: 'עברית',
  id: 'Bahasa Indonesia',
  ms: 'Bahasa Melayu',
};

export interface LanguageOption {
  code: string;
  name: string;
}

/** Full language list (all known languages). */
export const ALL_LANGUAGES: LanguageOption[] = Object.entries(LANGUAGE_LABELS).map(
  ([code, name]) => ({ code, name })
);

/** Filter the full list to only the allowed codes (preserving order from ALL_LANGUAGES). */
export function filterLanguages(allowedCodes: string[]): LanguageOption[] {
  return ALL_LANGUAGES.filter((l) => allowedCodes.includes(l.code));
}
// #endregion Languages
