"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.hasKey = hasKey;
exports.translate = translate;
// Use JSON locale files (RN Metro supports static requires reliably)
// eslint-disable-next-line @typescript-eslint/no-var-requires
const enUS = require('./locales/en-US.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const esES = require('./locales/es-ES.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const caES = require('./locales/ca-ES.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const frFR = require('./locales/fr-FR.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const deDE = require('./locales/de-DE.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const itIT = require('./locales/it-IT.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ptPT = require('./locales/pt-PT.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const jaJP = require('./locales/ja-JP.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const koKR = require('./locales/ko-KR.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const zhCN = require('./locales/zh-CN.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const arSA = require('./locales/ar-SA.json');
const DICTS = {
  'en': enUS,
  'en-US': enUS,
  'es': esES,
  'es-ES': esES,
  'ca': caES,
  'ca-ES': caES,
  'fr': frFR,
  'fr-FR': frFR,
  'de': deDE,
  'de-DE': deDE,
  'it': itIT,
  'it-IT': itIT,
  'pt': ptPT,
  'pt-PT': ptPT,
  'ja': jaJP,
  'ja-JP': jaJP,
  'ko': koKR,
  'ko-KR': koKR,
  'zh': zhCN,
  'zh-CN': zhCN,
  'ar': arSA,
  'ar-SA': arSA
};
const FALLBACK = 'en-US';
function getNested(obj, path) {
  return path.split('.').reduce((acc, key) => acc && acc[key] != null ? acc[key] : undefined, obj);
}
function translate(locale, key, vars) {
  const lang = locale && DICTS[locale] ? locale : FALLBACK;
  const dict = DICTS[lang] || DICTS[FALLBACK];
  let val = getNested(dict, key);
  if (typeof val !== 'string') return key; // fallback to key if missing
  if (vars) {
    Object.keys(vars).forEach(k => {
      const token = `{{${k}}}`;
      val = val.replaceAll(token, String(vars[k]));
    });
  }
  return val;
}
function hasKey(locale, key) {
  const lang = locale && DICTS[locale] ? locale : FALLBACK;
  return getNested(DICTS[lang], key) != null || getNested(DICTS[FALLBACK], key) != null;
}
//# sourceMappingURL=index.js.map