import { computed as s, unref as g, inject as b } from "vue";
import { getChannelAccentColor as C } from "../../functions/getChannelAccentColor.js";
import "../../functions/parseMarkdown.js";
function I(o, l = 0.6) {
  const n = o.replace("#", ""), u = parseInt(n.substring(0, 2), 16), r = parseInt(n.substring(2, 4), 16), a = parseInt(n.substring(4, 6), 16);
  return `rgba(${u}, ${r}, ${a}, ${l})`;
}
function y(o) {
  if (typeof document > "u")
    return !1;
  if (o) {
    const n = document.getElementById(o);
    return (n == null ? void 0 : n.dataset.theme) === "glass";
  }
  return document.querySelector('[data-theme="glass"]') !== null;
}
function j(o, l = {}) {
  const { cssVariable: n, position: u = "right" } = l, r = s(() => g(o)), a = b("chatAppId", void 0), d = b("selectedChat", void 0), m = s(() => {
    if (d)
      return g(d);
  }), f = s(() => {
    const e = m.value, t = r.value;
    if (!(t != null && t.dialogId) || !(e != null && e.dialogs))
      return;
    const i = e.dialogs.find((v) => v.dialogId === t.dialogId);
    return i == null ? void 0 : i.channelId;
  }), h = s(() => {
    var e;
    return u === "both" ? !0 : (e = r.value) != null && e.position ? r.value.position === u : !1;
  }), c = s(() => {
    const e = r.value;
    if (!e || !h.value)
      return null;
    let t = null;
    return e.backgroundColor ? t = e.backgroundColor : t = C(f.value, null), t && y(a) && t.startsWith("#") ? I(t, 0.6) : t;
  }), p = s(() => !n || !c.value ? null : { [n]: c.value });
  return {
    bubbleColor: c,
    bubbleStyle: p,
    messageChannelId: f
  };
}
export {
  j as useChannelAccentColor
};
