'use strict';

require('../theme.js');
var direction = require('../direction.js');
require('../propsValues/control.js');
require('../propsValues/breakpoint.js');
require('../propsValues/size.js');
require('../propsValues/typography.js');
require('../propsValues/width.js');
require('../propsValues/type.js');
require('../propsValues/dateMode.js');
require('../propsValues/monthFormat.js');
require('../propsValues/position.js');
require('../propsValues/layouts.js');
require('../propsValues/status.js');
require('../propsValues/sentiment.js');
require('../propsValues/profileType.js');
require('../propsValues/variant.js');
require('../propsValues/scroll.js');
require('../propsValues/markdownNodeType.js');
require('../fileType.js');
require('@transferwise/icons');
require('clsx');
require('react');
require('react-intl');
require('../closeButton/CloseButton.messages.js');
require('react/jsx-runtime');

const DEFAULT_LANG = 'en';
const DEFAULT_LOCALE = 'en-GB';
/**
 * Languages written right-to-left.
 */
const RTL_LANGUAGES = ['ar', 'he'];
/**
 * @deprecated The source of truth for supported languages lives in Crab.
 */
const SUPPORTED_LANGUAGES = [DEFAULT_LANG, 'de', 'es', 'fr', 'hu', 'id', 'it', 'ja', 'pl', 'pt', 'ro', 'ru', 'th', 'tr', 'uk', 'zh'];
/**
 * Verifies and adjusts locale, replacing `_` with `-`.
 *
 * @param locale `es`, `es_ES`, `en-GB`, `en`, `ja`, `ja-JP`, etc.
 * @returns `null` if locale is unrecognized by `Intl.Locale`.
 */
function adjustLocale(locale) {
  const localeTrimmed = locale?.trim();
  if (localeTrimmed) {
    try {
      return new Intl.Locale(localeTrimmed.replace('_', '-')).baseName;
    } catch (error) {
      // eslint-disable-next-line no-console
      console.error(error);
    }
  }
  return null;
}
/**
 * Provides corresponding lang (iso2) for provided locale.
 *
 * @deprecated The use of this function almost always breaks language variants
 * e.g. Simplified and Traditional Chinese.
 * There should be no use case for this function.
 * To select the correct translations from a translations object, pass the
 * locale directly into Crab's getLocalisedMessages.
 * @param locale `es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP`, etc.
 * @returns Two-letter ISO 639-1 language code, falling back to `null` if locale is invalid or language is unsupported.
 */
function getLangFromLocale(locale) {
  const adjustedLocale = adjustLocale(locale);
  if (adjustedLocale != null) {
    const {
      language
    } = new Intl.Locale(adjustedLocale);
    if (SUPPORTED_LANGUAGES.includes(language)) {
      return language;
    }
  }
  return null;
}
/**
 * Provides corresponding country code (iso2) for locales code with explicit region value.
 *
 * @param locale `es-ES`, `en-GB`, `ja-JP`, etc.
 * @returns `null` if the locale is invalid or the region can‘t be identified.
 */
function getCountryFromLocale(locale) {
  const adjustedLocale = adjustLocale(locale);
  return adjustedLocale != null ? new Intl.Locale(adjustedLocale).region ?? null : null;
}
/**
 * Provides the layout direction for a given locale.
 *
 * @param locale `es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP`, etc.
 * @returns The layout direction based on the locale, falling back to `Direction.LTR` if the locale is invalid or unsupported.
 */
function getDirectionFromLocale(locale) {
  const adjustedLocale = adjustLocale(locale);
  return adjustedLocale != null && RTL_LANGUAGES.includes(new Intl.Locale(adjustedLocale).language) ? direction.Direction.RTL : direction.Direction.LTR;
}

exports.DEFAULT_LANG = DEFAULT_LANG;
exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
exports.RTL_LANGUAGES = RTL_LANGUAGES;
exports.SUPPORTED_LANGUAGES = SUPPORTED_LANGUAGES;
exports.adjustLocale = adjustLocale;
exports.getCountryFromLocale = getCountryFromLocale;
exports.getDirectionFromLocale = getDirectionFromLocale;
exports.getLangFromLocale = getLangFromLocale;
//# sourceMappingURL=index.js.map
