import { l as g } from "./logger.mjs";
import "@seamless/logger";
import { L as c, a as f } from "./initializeLogger.mjs";
import "@seamless/store";
import "@b2x/std/helpers.mjs";
import { t as A, g as I } from "./get-environment-data.mjs";
import { getTranslation as E } from "@owc/aem-translations-util";
import { CROWDIN_PROJECT_BASE_URL as d } from "../constants.mjs";
import "@owc/aem-component-data-util";
const _ = "locales", m = "translations", w = "localesTimestamp", C = 1440 * 60 * 1e3;
let u, T;
const $ = async (t) => {
  u = `${m}.${t}.${_}`, T = `${m}.${t}.${w}`;
  const a = localStorage.getItem(u), e = localStorage.getItem(T);
  if (a && e) {
    const o = new Date(e);
    if ((/* @__PURE__ */ new Date()).getTime() - o.getTime() < C)
      return JSON.parse(a);
  }
  return await h(t);
};
async function h(t) {
  const a = `${d}/${t}/manifest.json`, { data: e, error: o } = await A(
    (async () => (await fetch(a, {
      method: "GET",
      headers: {
        "Content-Type": "application/json"
      }
    })).json())()
  ), n = e?.languages ?? [];
  return o || !n.length ? (g("Error fetching i18n locales", {
    args: [o ?? "Locales require to be fetched after a timeout"],
    group: f.TRANSLATION,
    level: o ? c.ERROR : c.INFO
  }), []) : (localStorage.setItem(u, JSON.stringify(n)), localStorage.setItem(T, (/* @__PURE__ */ new Date()).toISOString()), n);
}
const N = async (t, a) => {
  const e = await $(a), [o] = t.split("-");
  return e.includes(t) || e.includes(o);
}, S = "GB", L = "en", r = `${L}-${S}`;
let s = r;
const i = /* @__PURE__ */ new Map();
async function B(t, a) {
  const { country: e = S, language: o = L } = (await I(a)).pageEnvironmentVariables;
  s = `${o}-${e}`;
  let n = await N(s, t);
  if (!n) {
    if (s = r, n = await N(s, t), !n)
      return g(
        `Neither ${s} nor the default locale ${r} translations were found. No translations will be loaded.`,
        {
          args: [],
          level: c.INFO,
          group: f.TRANSLATION
        }
      ), i;
    g(`Translations for ${s} were not found, falling back to default locale ${r}.`, {
      args: [],
      level: c.INFO,
      group: f.TRANSLATION
    });
  }
  return await O(r, t), s === r || await O(s, t), i;
}
function y(t) {
  const a = Object.values(t), e = {};
  for (const o of a)
    e[o.identifier] = o.translation;
  return e;
}
const O = async (t, a) => {
  try {
    i.set(t, {
      locale: t,
      messages: {
        [t]: y(await E(t, a))
      }
    });
  } catch (e) {
    g(`Error fetching translations for ${t}.`, {
      args: [e],
      level: c.INFO,
      group: f.TRANSLATION
    });
  }
};
function M() {
  const { locale: t, messages: a } = i.get(s) ?? { locale: "unknown", messages: {} }, { locale: e, messages: o } = i.get(r) ?? {
    locale: "unknown",
    messages: {}
  }, n = a[t] || {}, p = o[e] || {};
  return {
    exist: (l) => l in n || l in p,
    t: (l) => n[l] || p[l] || l,
    availableLocales: [t],
    locale: t
  };
}
const U = {
  PRIVATE: "profile.context.private.registered",
  COMPANY: "profile.context.company.registered",
  GUEST_PRIVATE: "profile.context.private.guest",
  GUEST_COMPANY: "profile.context.company.guest",
  ADD_COMPANY: "profile.context.company.add",
  NOT_AVAILABLE: "profile.context.not.available",
  NOTIFICATIONS_PROFILES_NOT_AVAILABLE: "profile.context.notifications.profilesNotAvailable",
  PROFILE_NOT_AVAILABLE: "profile.context.not.available",
  NOTIFICATIONS_CONTEXT_CHANGE_PRIVATE: "profile.context.notification.change.private",
  NOTIFICATIONS_CONTEXT_CHANGE_BUSINESS: "profile.context.notification.change.business",
  NOTIFICATIONS_CONTEXT_CHANGE_BUSINESS_GUEST: "profile.context.notification.change.business.guest",
  LOGIN: "profile.context.navigation.login"
};
export {
  U as P,
  B as l,
  M as u
};
//# sourceMappingURL=profileContextKeys.mjs.map
