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