import { RawBundleSource as i, LocaleManager as u, useI18N as l } from "@dialpad/i18n-vue2";
import f from "./en-US.js";
import d from "./zh-CN.js";
import m from "./nl-NL.js";
import p from "./fr-FR.js";
import g from "./de-DE.js";
import w from "./it-IT.js";
import N from "./ja-JP.js";
import S from "./pt-BR.js";
import L from "./ru-RU.js";
import R 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"
}, n = "en-US";
class o {
  constructor(r = null) {
    if (typeof o.instance == "object")
      return o.instance;
    this._locale = r || o.getPreferredLocale();
    const a = new i({
      resources: i.builtResources([
        ["en-US", e, f],
        ["zh-CN", e, d],
        ["nl-NL", e, m],
        ["fr-FR", e, p],
        ["de-DE", e, g],
        ["it-IT", e, w],
        ["ja-JP", e, N],
        ["pt-BR", e, S],
        ["ru-RU", e, L],
        ["es-LA", e, R]
      ])
    });
    return new u({
      bundleSource: a,
      allowedLocales: Object.values(t),
      fallbackLocale: n,
      preferredLocale: this._locale,
      namespaces: [e]
    }).install(e), o.instance = this, typeof window < "u" && (window.onstorage = (c) => {
      c.key === "user-locale" && (this.currentLocale = c.newValue);
    }), this;
  }
  static getPreferredLocale() {
    if (typeof window > "u" || !window.localStorage)
      return n;
    const r = window.localStorage.getItem("user-locale"), a = Object.values(t).find((s) => s.startsWith(navigator.language.slice(0, 2)));
    return r || a || n;
  }
  static getAllowedLocales() {
    return t;
  }
  $t(...r) {
    return l(e).$t(...r);
  }
  $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
