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