import { d as i, A as P, s as O, p as W } from "./FetchConfigsUtils-476a602b.mjs";
import { z as e } from "zod";
import { P as x, L as U, B as w, C as z, G as _, a as E, S as K, T as S } from "./useDiscoveryConfigs-cf63cd60.mjs";
const c = class {
};
let l = c;
l.normalizeColor = (t) => t > 255 ? 255 : t < 0 ? 0 : t;
l.getHexWithoutHash = (t) => {
  let a = t.replace("#", "");
  return a.length === 3 && (a = `${t[0]}${t[0]}${t[1]}${t[1]}${t[2]}${t[2]}`), a;
};
l.hexToRGB = (t) => {
  const a = c.getHexWithoutHash(t), n = parseInt(a.substring(0, 2), 16), o = parseInt(a.substring(2, 4), 16), s = parseInt(a.substring(4, 6), 16);
  return `${n},${o},${s}`;
};
l.shadeColor = (t, a) => {
  const n = c.getHexWithoutHash(t), o = parseInt(n, 16), s = c.normalizeColor((o >> 16) + a), u = c.normalizeColor((o & 255) + a), b = c.normalizeColor((o >> 8 & 255) + a);
  return `#${(u | b << 8 | s << 16).toString(16)}`;
};
l.lightenColor = (t, a) => c.shadeColor(t, a);
l.darkenColor = (t, a) => c.shadeColor(t, a * -1);
const D = "odin-styles", f = class {
  static bgOverlayToCss(t, a = ":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(`
`)), `${a} {${n}}`;
  }
  static colorConfigToCss(t, a = ":root") {
    const n = Object.entries(t).map(([o, s]) => {
      if (!(s != null && s.rgb))
        return null;
      const u = [], { r: b, g: I, b: y, a: B } = s.rgb, d = `${b},${I},${y}`;
      if (o === "primary") {
        const p = l.lightenColor(s.hex, 90), j = l.hexToRGB(p), F = `--od-rgb-${o}-20: ${j};`, v = l.lightenColor(s.hex, 70), $ = l.hexToRGB(v), L = `--od-rgb-${o}-40: ${$};`, N = l.lightenColor(s.hex, 50), R = l.hexToRGB(N), A = `--od-rgb-${o}-60: ${R};`;
        u.push(F, L, A);
      }
      if (o === "text") {
        const p = `--od-rgba-${o}-default: ${d}, 0.65;`;
        u.push(p);
      }
      const h = `
        --od-rgba-${o}: ${d},${B};
        --od-rgb-${o}: ${d};
        --od-a-${o}: ${B};
        `;
      return u.push(h), u.join(`
`);
    }).filter((o) => !!o).join(`
`);
    return `${a} {${n}}`;
  }
  static fontConfigToCssVar(t, a = ":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 `${a} {${n}}`;
  }
  static generateImports(t) {
    return [(t == null ? void 0 : t.customBodyFontUrl) ?? "", (t == null ? void 0 : t.customTitleFontUrl) ?? ""].filter(Boolean).map((a) => `@import url('${a}');`).join("");
  }
};
let g = f;
g.injectCss = (t) => {
  const a = document.getElementById(D), n = a ?? document.createElement("style");
  n.id = D, n.innerHTML = t, a || document.head.appendChild(n);
};
g.removeInjectedCss = () => {
  const t = document.getElementById(D);
  t && t.remove();
};
g.extractFontNameFromFontUrl = (t) => {
  var a;
  try {
    return ((a = new URL(t).searchParams.get("family")) == null ? void 0 : a.replace(/:.*/, "")) || null;
  } catch {
    return null;
  }
};
g.convertConfigToCss = (t) => {
  var d, h, p, j, F, v, $, L;
  const a = (h = (d = t == null ? void 0 : t.data) == null ? void 0 : d.global) == null ? void 0 : h.fonts, n = f.fontConfigToCssVar(a), o = f.generateImports(a), s = ((j = (p = t == null ? void 0 : t.data) == null ? void 0 : p.global) == null ? void 0 : j.colors) ?? {}, u = f.colorConfigToCss(s), b = { id: "main", ...(v = (F = t == null ? void 0 : t.data) == null ? void 0 : F.mainPage) == null ? void 0 : v.backgroundOverlay }, I = { id: "login", ...(L = ($ = t == null ? void 0 : t.data) == null ? void 0 : $.loginPage) == null ? void 0 : L.backgroundOverlay }, y = f.bgOverlayToCss([b, I]);
  return [o, u, y, n].join(" ");
};
const J = e.object({
  isKnowledgeBaseEnabled: e.boolean()
}), M = e.object({
  email: e.string(),
  isUseExternalSupportEnabled: e.boolean(),
  externalSupportURL: e.string()
}), Y = e.object({
  isPlayerPortalEnabled: e.boolean(),
  isLauncherEnabled: e.boolean()
}), q = e.object({
  isDisabled: e.boolean(),
  redirectionURL: e.string(),
  siteBrandURL: e.string()
}), Q = e.object({
  id: e.string(),
  name: e.string(),
  link: e.string()
}), V = e.object({
  links: e.array(Q)
});
e.object({
  launcherDownloadLink: i.merge(
    e.object({
      data: e.object({
        value: e.string()
      })
    })
  ),
  metaData: i.merge(
    e.object({
      data: e.object({
        description: e.string(),
        image: e.string(),
        title: e.string()
      })
    })
  ),
  pageConfig: i.merge(
    e.object({
      data: x
    })
  ),
  footer: i.merge(
    e.object({
      data: e.object({
        value: V
      })
    })
  ),
  homepage: i.merge(
    e.object({
      data: q
    })
  ),
  logoVariant: i.merge(
    e.object({
      data: U
    })
  )
});
const T = e.enum(["gameId", "gameName", "namespace", "clientId"]), k = e.object({
  games: e.array(
    e.object({
      [T.enum.gameId]: e.string(),
      [T.enum.gameName]: e.string(),
      [T.enum.namespace]: e.string(),
      [T.enum.clientId]: e.string()
    })
  )
}), G = e.object({
  isStreamButtonEnabled: e.boolean(),
  streamButton: e.object({
    label: e.string(),
    url: e.string()
  })
});
e.object({
  logoVariant: i.merge(
    e.object({
      data: e.object({
        header: e.number().nullable()
      })
    })
  ),
  gameList: i.merge(
    e.object({
      data: k
    })
  ),
  streamerInfo: i.merge(
    e.object({
      data: G
    })
  ),
  backgroundConfig: i.merge(
    e.object({
      data: w
    })
  ),
  pageConfig: e.optional(
    i.merge(
      e.object({
        data: x
      })
    )
  )
});
const X = W, at = e.object({
  launcherDownloadLink: e.object({
    value: e.string()
  }),
  metaData: e.object({
    description: e.string(),
    image: e.string(),
    title: e.string()
  }).nullish(),
  footer: e.object({
    value: V
  }),
  logoVariant: U
}), ot = e.object({
  appId: e.object({
    value: e.string()
  }),
  avatarsList: e.object({
    value: e.array(e.string())
  }),
  brandName: e.object({
    value: e.string()
  }),
  pageTitle: e.object({
    value: e.string()
  }),
  companyLogo: z,
  copyright: e.object({
    value: e.string()
  }),
  experimentalFeatureFlags: e.record(e.boolean()),
  globalPageConfig: _,
  ppFeatureFlags: E.omit({
    isNotificationsVisible: !0,
    isNewsVisible: !0,
    isSubscriptionsVisible: !0,
    isVirtualCurrencyVisible: !0,
    isNewsV2Visible: !0
  }).partial(),
  supportFeatureFlags: e.record(e.boolean()),
  socialLinks: e.object({
    value: e.array(K)
  }),
  templateConfig: e.object({
    value: e.union([e.literal(`${S.SINGLE}`), e.literal(`${S.MULTIPLE}`)])
  })
}), rt = e.object({
  logoVariant: e.object({
    header: e.number().nullable()
  }),
  gameList: k,
  streamerInfo: G,
  backgroundConfig: w
}), nt = e.object({
  knowledgeBaseSettings: J,
  displayCTAButton: Y,
  submissionForm: M
}), H = class {
};
let m = H;
m.createDiscoveryConfigs = (t) => {
  if (t)
    return {
      appId: r(t.appId),
      avatarsList: r({
        value: t.avatarsList.value.join(`
`)
      }),
      brandName: r(t.brandName),
      pageTitle: r(t.pageTitle),
      companyLogo: r(t.companyLogo),
      copyright: r(t.copyright),
      experimentalFeatureFlags: r(t.experimentalFeatureFlags),
      favicon: r({
        value: ""
      }),
      globalPageConfig: r(t.globalPageConfig),
      launcherFeatureFlags: r({}),
      launcherTemplateInfo: C(),
      legalTemplateInfo: C(),
      loginFeatureFlags: r({}),
      loginTemplateInfo: C(),
      paymentTemplateInfo: C(),
      ppFeatureFlags: r(E.parse(t.ppFeatureFlags)),
      ppTemplateInfo: r({
        draft: "pp-default",
        published: "pp-default"
      }),
      supportFeatureFlags: r(t.supportFeatureFlags),
      socialLinks: r(t.socialLinks),
      templateConfig: r(t.templateConfig),
      twitchDropTemplateInfo: r({
        draft: "twitchdrop-default",
        published: "twitchdrop-default"
      }),
      supportTemplateInfo: C(),
      launcherIcon: r({
        value: ""
      })
    };
};
m.createPlayerPortalConfigs = (t) => {
  var a, n, o;
  if (t)
    return {
      footer: r(t.footer),
      homepage: r({
        isDisabled: !1,
        redirectionURL: "",
        siteBrandURL: ""
      }),
      launcherDownloadLink: r(t.launcherDownloadLink),
      logoVariant: r(t.logoVariant),
      metaData: r({
        description: ((a = t.metaData) == null ? void 0 : a.description) || "",
        image: ((n = t.metaData) == null ? void 0 : n.image) || "",
        title: ((o = t.metaData) == null ? void 0 : o.title) || ""
      }),
      pageConfig: r(X.pageConfig.data)
    };
};
m.createTwitchDropConfigs = (t) => {
  if (t)
    return {
      logoVariant: r(t.logoVariant),
      gameList: r(t.gameList),
      streamerInfo: r(t.streamerInfo),
      backgroundConfig: r(t.backgroundConfig)
    };
};
m.createSupportConfigs = (t) => {
  if (t)
    return {
      knowledgeBaseSettings: r(t.knowledgeBaseSettings),
      displayCTAButton: r(t.displayCTAButton),
      submissionForm: r(t.submissionForm),
      pageConfig: r(O.pageConfig.data)
    };
};
m.getAppId = (t) => (t == null ? void 0 : t.appId.data.value) || "";
m.isSingleGame = (t) => t === S.SINGLE;
m.injectCss = (t, a) => {
  const n = a.data.isLocalStyleEnabled, o = t.globalPageConfig;
  let s = "";
  n ? s = g.convertConfigToCss(a) : o && (s = g.convertConfigToCss(o)), H.isSingleGame(t.templateConfig.data.value) ? g.injectCss(s) : g.injectCss("");
};
m.getFeatureFlags = (t, a) => {
  let n = null;
  switch (a) {
    case P.WIDGET:
      n = { ...t.ppFeatureFlags.data, ...t.experimentalFeatureFlags.data };
      break;
    case P.LAUNCHER:
      n = {
        ...t.launcherFeatureFlags.data,
        ...t.experimentalFeatureFlags.data,
        ...t.supportFeatureFlags.data
      };
      break;
  }
  return n;
};
function r(t) {
  return {
    data: t,
    format: "",
    name: "",
    updatedAt: "",
    version: 0
  };
}
function C() {
  return r({
    draft: "",
    published: ""
  });
}
function st(t) {
  return new Promise((a) => {
    setTimeout(() => a(void 0), t);
  });
}
export {
  g as A,
  m as C,
  ot as S,
  at as a,
  rt as b,
  nt as c,
  st as w
};
