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