import { detectLocale as z } from "@feedmepos/mf-common";
const y = new RegExp("\\p{L}[\\p{L}\\p{N}]*", "gu"), A = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
function L(r) {
  const n = r.replace(/([A-Za-z0-9])_([A-Za-z0-9])/g, "$1 $2");
  return n.charAt(0).toUpperCase() + n.slice(1);
}
function l(r, n) {
  return A.test(n) ? `${r}.${n}` : `${r}[${JSON.stringify(n)}]`;
}
function $(r) {
  return r && r.charAt(0).toUpperCase() + r.slice(1);
}
function W(r) {
  return Array.from(
    /* @__PURE__ */ new Set([
      r,
      r.toLowerCase(),
      r.toUpperCase(),
      $(r),
      $(r.toLowerCase())
    ])
  );
}
function S(r) {
  return r.replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2");
}
function Z(r, n, t) {
  const i = W(t);
  for (const e of i) {
    const a = [
      `report.dynamic.schema.${e}`,
      `report.dynamic.common.${e}`,
      `report.common.${e}`,
      `report.dynamic.other[${JSON.stringify(e)}]`
    ];
    for (const o of a)
      if (n(o))
        return r(o);
  }
  return t;
}
function m(r, n, t) {
  const i = S(t);
  let e = !1;
  const a = i.replace(y, (o) => {
    const s = Z(r, n, o);
    return s !== o && (e = !0), s;
  });
  return e ? a : "";
}
function C(r, n, t, i) {
  if (!t)
    return t || "";
  const e = t.trim(), a = ["report", "dynamic"];
  i && a.push(i);
  const o = a.join("."), s = l(o, e);
  if (n(s))
    return r(s);
  const c = z();
  if (c === "en-US")
    return t;
  const d = m(r, n, e);
  if (d)
    return d;
  if (c !== "en-US") {
    const u = L(e), f = l(o, u);
    if (n(f))
      return r(f);
    const p = m(r, n, u);
    return p || t;
  }
  return t;
}
export {
  C as r
};
