import { I18N_CONFIG } from "./config/index.js";
function isValidLocale(locale) {
  return I18N_CONFIG.supportedLocales.includes(locale);
}
function getSafeLocale(locale) {
  if (!locale) return I18N_CONFIG.defaultLocale;
  return isValidLocale(locale) ? locale : I18N_CONFIG.defaultLocale;
}
function validateTranslationKey(messages, key, locale) {
  const keys = key.split(".");
  let current = messages;
  for (const k of keys) {
    if (!(current == null ? void 0 : current[k])) {
      console.warn(`Missing translation key "${key}" for locale "${locale}"`);
      return false;
    }
    current = current[k];
  }
  return true;
}
function detectMissingTranslations(enMessages, esMessages, path = "") {
  const missing = [];
  function checkMessages(en, es, currentPath) {
    for (const key in en) {
      const newPath = currentPath ? `${currentPath}.${key}` : key;
      if (typeof en[key] === "object" && en[key] !== null) {
        if (!es[key] || typeof es[key] !== "object") {
          missing.push(newPath);
        } else {
          checkMessages(en[key], es[key], newPath);
        }
      } else {
        if (!es[key]) {
          missing.push(newPath);
        }
      }
    }
  }
  checkMessages(enMessages, esMessages, path);
  return missing;
}
export {
  detectMissingTranslations,
  getSafeLocale,
  isValidLocale,
  validateTranslationKey
};
