"use strict";

// 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');
const DICTS = {
  'en': enUS,
  'en-US': enUS,
  'es': esES,
  'es-ES': esES
};
const FALLBACK = 'en-US';
function getNested(obj, path) {
  return path.split('.').reduce((acc, key) => acc && acc[key] != null ? acc[key] : undefined, obj);
}
export 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;
}
export 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