import { RawBundleSource as i, LocaleManager as f, useI18N as l } from "@dialpad/i18n";
import { getCurrentInstance as p } from "vue";
import m from "./en-US.js";
import d from "./zh-CN.js";
import g from "./nl-NL.js";
import S from "./fr-FR.js";
import w from "./de-DE.js";
import N from "./it-IT.js";
import L from "./ja-JP.js";
import R from "./pt-BR.js";
import h from "./ru-RU.js";
import E from "./es-LA.js";
const e = "dialtone", t = {
  ENGLISH: "en-US",
  CHINESE: "zh-CN",
  DUTCH: "nl-NL",
  FRENCH: "fr-FR",
  GERMAN: "de-DE",
  ITALIAN: "it-IT",
  JAPANESE: "ja-JP",
  PORTUGUESE: "pt-BR",
  RUSSIAN: "ru-RU",
  SPANISH: "es-LA"
}, s = "en-US", u = "user-locale";
class o {
  constructor(r = null) {
    if (typeof o.instance == "object")
      return o.instance;
    const a = p().appContext.app;
    this._locale = r || o.getPreferredLocale();
    const n = new i({
      resources: i.builtResources([
        ["en-US", e, m],
        ["zh-CN", e, d],
        ["nl-NL", e, g],
        ["fr-FR", e, S],
        ["de-DE", e, w],
        ["it-IT", e, N],
        ["ja-JP", e, L],
        ["pt-BR", e, R],
        ["ru-RU", e, h],
        ["es-LA", e, E]
      ])
    });
    return new f({
      bundleSource: n,
      allowedLocales: Object.values(t),
      fallbackLocale: s,
      preferredLocale: this._locale,
      namespaces: [e]
    }).install(a, e), o.instance = this, typeof window < "u" && (window.onstorage = (c) => {
      c.key === u && (this.currentLocale = c.newValue);
    }), this;
  }
  /**
   * Gets the preferred locale from user's locale stored in localStorage or the browser language
   * @returns { string }
   */
  static getPreferredLocale() {
    if (typeof window > "u" || !window.localStorage)
      return s;
    const r = window.localStorage.getItem(u), a = Object.values(t).find((n) => n.startsWith(navigator.language.slice(0, 2)));
    return r || a || s;
  }
  static getAllowedLocales() {
    return t;
  }
  /**
   * Passthrough function to the i18n $t function including the dialtone namespace
   * Returns a translated string based on a key and optional variables.
   * It’s used for simple text translations.
   * https://github.com/dialpad/goblin-client-tools/tree/main/packages/i18n#t
   */
  $t(...r) {
    return l(e).$t(...r);
  }
  /**
   * Passthrough function to the i18n $ta function including the dialtone namespace
   * Returns an object containing translated attributes to pass directly as props to components, it can contain
   * aria-label, title, etc, rather than just a plain text. It’s useful for handling element attributes in the UI.
   * https://github.com/dialpad/goblin-client-tools/tree/main/packages/i18n#ta
   */
  $ta(...r) {
    return l(e).$ta(...r);
  }
  get currentLocale() {
    return this._locale;
  }
  set currentLocale(r) {
    if (r !== this._locale) {
      if (!Object.values(t).includes(r))
        throw new Error(`Locale ${r} is not allowed, please use one of the following: ${Object.values(t).join(", ")}`);
      this._locale = r, l(e).setI18N({ preferredLocale: r }, e);
    }
  }
}
export {
  o as DialtoneLocalization
};
//# sourceMappingURL=index.js.map
