import { ColorUtils as c } from "./accelbyte-widgets323.mjs";
const C = "odin-styles", i = class {
  static bgOverlayToCss(t, r = ":root") {
    let n = "";
    return t.length > 0 && (n = t.map(({ id: o, opacity: s }) => !o || !s ? null : `--od-overlay-${o}-opacity: ${s / 100};`).filter((o) => !!o).join(`
`)), `${r} {${n}}`;
  }
  static colorConfigToCss(t, r = ":root") {
    const n = Object.entries(t).map(([o, s]) => {
      if (!(s != null && s.rgb))
        return null;
      const e = [], { r: y, g: B, b: T, a: x } = s.rgb, l = `${y},${B},${T}`;
      if (o === "primary") {
        const a = c.lightenColor(s.hex, 90), u = c.hexToRGB(a), m = `--od-rgb-${o}-20: ${u};`, $ = c.lightenColor(s.hex, 70), v = c.hexToRGB($), b = `--od-rgb-${o}-40: ${v};`, F = c.lightenColor(s.hex, 50), U = c.hexToRGB(F), f = `--od-rgb-${o}-60: ${U};`;
        e.push(m, b, f);
      }
      if (o === "text") {
        const a = `--od-rgba-${o}-default: ${l}, 0.65;`;
        e.push(a);
      }
      const d = `
        --od-rgba-${o}: ${l},${x};
        --od-rgb-${o}: ${l};
        --od-a-${o}: ${x};
        `;
      return e.push(d), e.join(`
`);
    }).filter((o) => !!o).join(`
`);
    return `${r} {${n}}`;
  }
  static fontConfigToCssVar(t, r = ":root") {
    const n = ["title", "body"].map((o) => {
      const s = o === "body" ? "customBodyFontUrl" : "customTitleFontUrl";
      return `--od-font-${o}: "${this.extractFontNameFromFontUrl(t[s]) || t[o]}";`;
    }).join(`
`);
    return `${r} {${n}}`;
  }
  static generateImports(t) {
    const r = /* @__PURE__ */ new Set();
    return r.add(t.customBodyFontUrl ?? ""), r.add(t.customTitleFontUrl ?? ""), Array.from(r).filter(Boolean).map((n) => `@import url('${n}');`).join("");
  }
};
let h = i;
h.injectCss = (t) => {
  const r = document.getElementById(C), n = r ?? document.createElement("style");
  n.id = C, n.innerHTML = t, r || document.head.appendChild(n);
};
h.removeInjectedCss = () => {
  const t = document.getElementById(C);
  t && t.remove();
};
h.extractFontNameFromFontUrl = (t) => {
  var r;
  try {
    return ((r = new URL(t).searchParams.get("family")) == null ? void 0 : r.replace(/:.*/, "")) || null;
  } catch {
    return null;
  }
};
h.convertConfigToCss = (t) => {
  var l, d, a, u, m, $, v, b;
  const r = (d = (l = t == null ? void 0 : t.data) == null ? void 0 : l.global) == null ? void 0 : d.fonts, n = i.fontConfigToCssVar(r), o = i.generateImports(r), s = ((u = (a = t == null ? void 0 : t.data) == null ? void 0 : a.global) == null ? void 0 : u.colors) ?? {}, e = i.colorConfigToCss(s), y = { id: "main", ...($ = (m = t == null ? void 0 : t.data) == null ? void 0 : m.mainPage) == null ? void 0 : $.backgroundOverlay }, B = { id: "login", ...(b = (v = t == null ? void 0 : t.data) == null ? void 0 : v.loginPage) == null ? void 0 : b.backgroundOverlay }, T = i.bgOverlayToCss([y, B]);
  return [o, e, T, n].join(" ");
};
export {
  h as AppBuilderUtils,
  C as INJECTED_STYLES_ID
};
