var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
import { parse } from "@formatjs/icu-messageformat-parser";
const _DictionaryCache = class {
  constructor(dictionary) {
    this.dictionary = dictionary;
  }
  getMessageAST(key) {
    let keyCache = _DictionaryCache.astCacheByDictionary.get(this.dictionary);
    if (keyCache === void 0) {
      _DictionaryCache.astCacheByDictionary.set(this.dictionary, keyCache = /* @__PURE__ */ new Map());
    }
    let ast = keyCache.get(key);
    if (ast === void 0) {
      const message = this.getDictionaryMessage(this.dictionary, key);
      if (message === void 0) {
        return void 0;
      }
      ast = parse(message);
      keyCache.set(key, ast);
    }
    return ast;
  }
  getOriginalMessageForDebuggingPurposes(key) {
    return this.getDictionaryMessage(this.dictionary, key);
  }
  getDictionaryMessage(dictionary, key) {
    if (key in dictionary) {
      const message = dictionary[key];
      return typeof message === "string" ? message : void 0;
    }
    const propertyPath = key.split(".");
    for (const [i, property] of propertyPath.entries()) {
      if (property in dictionary) {
        const message = dictionary[property];
        if (typeof message === "string") {
          if (i === propertyPath.length - 1) {
            return message;
          }
          return void 0;
        }
        dictionary = message;
      } else {
        return void 0;
      }
    }
  }
};
let DictionaryCache = _DictionaryCache;
__publicField(DictionaryCache, "astCacheByDictionary", /* @__PURE__ */ new WeakMap());
export { DictionaryCache };
//# sourceMappingURL=DictionaryCache.js.map
