function o(e, a, n = 0) {
  const { length: r } = e;
  return n < 0 ? n = 0 : n > r && (n = r), a = `${a}`, e.slice(n, n + a.length) == a;
}
function u() {
  return typeof window > "u" ? null : window.navigator.languages && window.navigator.languages[0] || window.navigator.language || // @ts-expect-error
  window.navigator.browserLanguage || // @ts-expect-error
  window.navigator.userLanguage || // @ts-expect-error
  window.navigator.systemLanguage || null;
}
function l(e) {
  return (e || "").toLowerCase().replace(/-/, "_");
}
function w(e) {
  if (!e)
    return u();
  const { languages: a, fallback: n } = e;
  if (!e.languages)
    return n;
  const r = l(u());
  if (!r)
    return n;
  const t = a.filter((g) => l(g) === r);
  return t.length > 0 ? t[0] || n : a.filter((g) => o(r, g))[0] || n;
}
export {
  w as default
};
